Re: question about key generation

From: Roman D (dostic..mail.com)
Date: Wed Feb 23 2005 - 15:48:27 EST

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

    Thanks Andrus,

    To put in the practical way; Let's say I'm developing application with
    Mysql, then I deploy it to production server running Oracle.
    I can't use "Cayenne Generated Primary Key" because database structure
    will be diffrent on difrent DB types -on mysql column type will have
    auto_increment and on Oracle it will have an additional sequence.

    Okay, then I should use "Generate Primary Key Support" (chapter 4.6). It
    seems like DB-independent, using an additional special "AUTO_PK_SUPPORT"
    sequence table[s].
    It's okay but what if I need to access same database from non-Cayenne
    solution or non-Java, like perl? (Though I can teach perl script to use
    "AUTO_PK_SUPPORT" but that's out of scope).

    What is the best practice to have database structure which is completely
    free of DB-specific features (e.g. not using mysql auto_increment or
    Oracle sequence) and is it possible without having Cayenne-specific
    "AUTO_PK_SUPPORT" tables?

    Thanks,
    Roman.

    Andrus Adamchik wrote:
    > 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 - 15:58:28 EST