Re: question about key generation

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 23 2005 - 14:21:09 EST

  • Next message: Orion Fields: "Synchronization/Deadlock"

    Hi Roman,

    What you describe as hilo algorithm used by Hibernate (I don't know how it
    actualy works, so my assumptions are based on your description) seems very
    uch the same as Cayenne auto-increment table. "data_seq" looks like that
    special table that you have to use to store current PK.

    Anyway, a few points here that will hopefully answer your questions.

    (1) It is true that by default Cayenne DbAdapters ship with different
    mechanisms for PK generation. But your application (and core DB schema) is
    still 100% portable across DB! Why would you care if on Oracle it uses a
    helper PK sequence, and on MySQL - a PK lookup table? That's external to
    your app. If you still see this as a problem, could you elaborate?

    (2) PK generation mechanism is abstracted in PkGenerator interface. If
    defaults are not desirable for any reason, you can easily configure
    Cayenne to use an alternative generator with any of the adapters. This can
    be one of the existing generators or your custom one.

    Cheers

    Andrus

    > Hi,
    >
    > I am Hibernate user and really want to migrate to Cayenne.
    >
    > My reasons to migrate are;
    > - Cayenne seem to have distributed "shared" cache support integrated. I
    > am developing multi-application that has separate struts and web
    > services application contexts. Cayenne, as I understand uses Javagroups
    > and you can configure it to have distributed cache.
    > With hibernate you have to use 3rd party cache (OSCache) and configure
    > it additionally.
    > - Easier higher-level syntax. In Hibernate you have make more
    > unnecessary method calls.
    > - Better community. Hibernate forums are full of two types of users-
    > total beginners or snobs who reply only if your problem look like a bug
    > in hibernate.
    >
    > I have a question about Cayenne key generation;
    > - Can I use Hilo-type key id generator with Cayenne?
    > According to chapter 4.7 Cayenne has "generated by Cayenne", provided by
    > database, derived.
    > In Hibernate you have a big choice of generators, you can use hilo,
    > uuid, increment, etc.
    >
    > I need to have portable key id generation. Portable to other DB and API.
    > In past, I have achieved it (with Hibernate) by using hilo: for table
    > "data", I have sequence table "data_seq" which have one field and one
    > record. Then I set in Hibernate mapping: generator="hilo"
    > table="data_seq". Hibernate increments and updates value in "data_seq"
    > table. This works with any possible database and is perfectly portable
    > to other APIs.
    >
    > Now with Cayenne I can't use native DB generators and auto_increment. I
    > also don't want to use Cayenne's "Generate Primary Key Support"
    > (Chapter 4.6) which uses special table and therefore it's
    > Cayenne-specific and not transparently portable to other API.
    >
    > Is there a way that I am missing?
    >
    > Thank you.
    > Roman.



    This archive was generated by hypermail 2.0.0 : Wed Feb 23 2005 - 14:21:11 EST