FAQ
Hi,

I'm looking into using Cayenne as a backend ORM technology
replacing hibernate. Currently our product supports multiple DBMSes (SQL
Server, Oracle, DB2) depending on what the client already has installed.
In hibernate when switching between oracle and sql server, for example, is
just a matter of changing the dialect. Is there a recommended way in
Cayenne to generate models in a generic way so that the backend DBMS can
be swapped out in code? (How is auto id generation effected? How are
stored procs. handled? etc.) I only see articles related to running
across multiple DBMSes.

Thanks.
-Mike

Search Discussions

  • Michael Gentry at Mar 23, 2010 at 7:04 pm
    You probably have a few options. The DataMap part of the model could
    mostly be reused. You could programatically create a DataNode (for
    your DB connection) and attach it to the DataMap or you could create
    the DataNode in the modeler and programatically adjust the settings in
    it. As for the PKs, you'd most likely need to iterate through the
    DataMap and set the PK Generation Strategy depending upon your
    DataNode type (the features used by your database: auto-increment,
    sequences, etc). Or, I suppose, you could use the generic
    AUTO_PK_SUPPORT table that Cayenne can generate for you.

    As for stored procedures ... Cayenne doesn't create/manage those for
    you, but you can define how to call the procedure in the modeler.

    I suspect I didn't really directly answer your questions, but perhaps
    gave you a few more things to think about to ask more questions. :-)

    mrg

    On Tue, Mar 23, 2010 at 2:40 PM, wrote:
    Hi,

    I'm looking into using Cayenne as a backend ORM technology
    replacing hibernate.  Currently our product supports multiple DBMSes (SQL
    Server, Oracle, DB2) depending on what the client already has installed.
    In hibernate when switching between oracle and sql server, for example, is
    just a matter of changing the dialect.  Is there a recommended way in
    Cayenne to generate models in a generic way so that the backend DBMS can
    be swapped out in code?  (How is auto id generation effected?  How are
    stored procs. handled?  etc.)  I only see articles related to running
    across multiple DBMSes.

    Thanks.
    -Mike
  • Andrus Adamchik at Mar 24, 2010 at 12:16 pm
    Cayenne project mapping is close to a 100% portable between different
    DB's as long as the DB's themselves are compatible. I guess the only
    piece that will need to change is DataNode connection info (and this
    can be delegated to container by using JNDI node).

    Now specific items:

    1. DbAdapter:
    Analog of Hibernate's dialect in Cayenne is DbAdapter. Cayenne has
    auto-detection of the DB type, so the correct DbAdapter is installed
    automatically. No need to change anything.

    2. PK generation:
    Auto ID generation mechanism may differ between DBs. It has to be
    installed on the target DB either manually before starting the app, or
    with some simple Cayenne code using DbGenerator class on startup. In
    any event, the differences between DB's are still abstracted and won't
    require mapping changes. E.g. for Oracle DbGenerator will create PK
    sequences, while for MySQL - a PK lookup table.

    3. Stored procedures:
    generally mappings should be portable, however different DB's may have
    incompatible formats for handling in/out parameters and returned
    result sets. So let's look at specific cases for me to comment more
    intelligently.

    Hope this helps.

    Andrus

    On Mar 23, 2010, at 8:40 PM, MGargano@escholar.com wrote:
    Hi,

    I'm looking into using Cayenne as a backend ORM technology
    replacing hibernate. Currently our product supports multiple DBMSes
    (SQL
    Server, Oracle, DB2) depending on what the client already has
    installed.
    In hibernate when switching between oracle and sql server, for
    example, is
    just a matter of changing the dialect. Is there a recommended way in
    Cayenne to generate models in a generic way so that the backend DBMS
    can
    be swapped out in code? (How is auto id generation effected? How are
    stored procs. handled? etc.) I only see articles related to running
    across multiple DBMSes.

    Thanks.
    -Mike
  • Mgargano at Mar 24, 2010 at 2:55 pm
    Thanks everyone. This is definitely making me feel more comfortable with
    Cayenne as an ORM choice. For #2 (PK Generation) below, does that mean I
    have to roll my own generator? Is there more detailed documentation on
    that (don't see it on the website)?

    Thanks again.
    -Mike




    From:
    Andrus Adamchik <andrus@objectstyle.org>
    To:
    user@cayenne.apache.org
    Date:
    03/24/2010 08:16 AM
    Subject:
    Re: Switching databases



    Cayenne project mapping is close to a 100% portable between different
    DB's as long as the DB's themselves are compatible. I guess the only
    piece that will need to change is DataNode connection info (and this
    can be delegated to container by using JNDI node).

    Now specific items:

    1. DbAdapter:
    Analog of Hibernate's dialect in Cayenne is DbAdapter. Cayenne has
    auto-detection of the DB type, so the correct DbAdapter is installed
    automatically. No need to change anything.

    2. PK generation:
    Auto ID generation mechanism may differ between DBs. It has to be
    installed on the target DB either manually before starting the app, or
    with some simple Cayenne code using DbGenerator class on startup. In
    any event, the differences between DB's are still abstracted and won't
    require mapping changes. E.g. for Oracle DbGenerator will create PK
    sequences, while for MySQL - a PK lookup table.

    3. Stored procedures:
    generally mappings should be portable, however different DB's may have
    incompatible formats for handling in/out parameters and returned
    result sets. So let's look at specific cases for me to comment more
    intelligently.

    Hope this helps.

    Andrus

    On Mar 23, 2010, at 8:40 PM, MGargano@escholar.com wrote:
    Hi,

    I'm looking into using Cayenne as a backend ORM technology
    replacing hibernate. Currently our product supports multiple DBMSes
    (SQL
    Server, Oracle, DB2) depending on what the client already has
    installed.
    In hibernate when switching between oracle and sql server, for
    example, is
    just a matter of changing the dialect. Is there a recommended way in
    Cayenne to generate models in a generic way so that the backend DBMS
    can
    be swapped out in code? (How is auto id generation effected? How are
    stored procs. handled? etc.) I only see articles related to running
    across multiple DBMSes.

    Thanks.
    -Mike
  • Michael Gentry at Mar 24, 2010 at 3:09 pm
    As long as you are using one of the standard PK generation schemes
    supported by Cayenne, you don't have to roll your own. If you want to
    do something special, like use a GUID type column that you calculate,
    then you'd have to create your own for that. I'm not sure if there is
    more detailed documentation (I don't recall any), but it is fairly
    simple to do now. Under the DataNode's Adapter tab in CM, you can
    specify a custom DbAdapter (subclass one of the Cayenne ones) and
    override the PK generator portions to use your custom PK generator. A
    friend of mine fairly new to Cayenne did this in less than an hour to
    generate his GUID values.

    mrg

    On Wed, Mar 24, 2010 at 10:54 AM, wrote:
    Thanks everyone.  This is definitely making me feel more comfortable with
    Cayenne as an ORM choice.  For #2 (PK Generation) below, does that mean I
    have to roll my own generator?  Is there more detailed documentation on
    that (don't see it on the website)?

    Thanks again.
    -Mike




    From:
    Andrus Adamchik <andrus@objectstyle.org>
    To:
    user@cayenne.apache.org
    Date:
    03/24/2010 08:16 AM
    Subject:
    Re: Switching databases



    Cayenne project mapping is close to a 100% portable between different
    DB's as long as the DB's themselves are compatible. I guess the only
    piece that will need to change is DataNode connection info (and this
    can be delegated to container by using JNDI node).

    Now specific items:

    1. DbAdapter:
    Analog of Hibernate's dialect in Cayenne is DbAdapter. Cayenne has
    auto-detection of the DB type, so the correct DbAdapter is installed
    automatically. No need to change anything.

    2. PK generation:
    Auto ID generation mechanism may differ between DBs. It has to be
    installed on the target DB either manually before starting the app, or
    with some simple Cayenne code using DbGenerator class on startup. In
    any event, the differences between DB's are still abstracted and won't
    require mapping changes. E.g. for Oracle DbGenerator will create PK
    sequences, while for MySQL - a PK lookup table.

    3. Stored procedures:
    generally mappings should be portable, however different DB's may have
    incompatible formats for handling in/out parameters and returned
    result sets. So let's look at specific cases for me to comment more
    intelligently.

    Hope this helps.

    Andrus

    On Mar 23, 2010, at 8:40 PM, MGargano@escholar.com wrote:
    Hi,

    I'm looking into using Cayenne as a backend ORM technology
    replacing hibernate.  Currently our product supports multiple DBMSes
    (SQL
    Server, Oracle, DB2) depending on what the client already has
    installed.
    In hibernate when switching between oracle and sql server, for
    example, is
    just a matter of changing the dialect.  Is there a recommended way in
    Cayenne to generate models in a generic way so that the backend DBMS
    can
    be swapped out in code?  (How is auto id generation effected?  How are
    stored procs. handled?  etc.)  I only see articles related to running
    across multiple DBMSes.

    Thanks.
    -Mike

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriescayenne
postedMar 23, '10 at 6:41p
activeMar 24, '10 at 3:09p
posts5
users3
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase