Re: Using Cayenne as a JPA provider in a Web Server

From: Andrus Adamchik (andru..bjectstyle.org)
Date: Wed Feb 21 2007 - 09:49:08 EST

  • Next message: Török Péte: "How to set default values or use triggers for a column?"

    Hi Lasantha,

    We started on the JPA Guide [1], but it doesn't have much user
    information yet. Would be nice to get it going, if possible - using
    your experience ;-) For now the procedure is roughly the following:

    * Build Cayenne trunk from source [2] (we need to start publishing
    snapshots asap, but alas - you have to build it now). Recently adding
    Geronimo and OpenEJB dependencies to the unit tests results in
    occasional build instability, so you'd probably have to do this:

    mvn -Dmaven.test.skip=true install

    and then do the assembly

    cd assembly
    mvn package

    * Cayenne distro is now under "cayenne/assembly/target/cayenne-3.0-
    SNAPSHOT.tar.gz", you can unpack it and grab the needed jars as
    described below.

    ... From here you can either use maven to declare Cayenne dependency
    or place needed jars in your app. I will discuss the second scenario,
    you can infer the first from it.

    * Place "lib/cayenne-agent-3.0-SNAPSHOT.jar" in the boot directory of
    the web container and add a "-javaagent:" option to the container
    startup script per [3].

    * Place the provider jar and its dependencies in the application (you
    can probably put it in a shared container path - I haven't tried it).
    The files are "lib/cayenne-server-3.0-SNAPSHOT.jar" and all the stuff
    under "lib/third-party".

    * Create "persistence.xml" in WEB-INF/classes of your app. There is
    probably no need to declare an explicit provider name, but you can
    still do that to ensure that Cayenne provider is used if you have
    more than one in the environment:

    <provider>org.apache.cayenne.jpa.Provider</provider>

    Also if you don't provide a mapping descriptor (i.e. use JPA
    annotations), you'll have to mention all your entities in
    persistence.xml under <class>..</class>.

    * Cayenne can take care of your DataSource creation per [4], or you
    can map a JNDI DataSource in Tomcat.

    * One big hole in Cayenne JPA implementation is EJBQL support. While
    we are working on that you can either use raw SQL queries, or limit
    your testing example to 'persist', 'find', 'remove' and other
    EntityManager methods that don't require EJBQL queries.

    Good luck , and don't hesitate to ask if you have questions or think
    you found a bug.

    Andrus

    [1] http://cayenne.apache.org/doc/jpa-guide.html
    [2] http://cayenne.apache.org/building-cayenne.html
    [3] http://cayenne.apache.org/doc/jpa-agent.html
    [4] http://cayenne.apache.org/doc/jpa-cayenne-provider-properties.html

    On Feb 21, 2007, at 3:07 PM, Lasantha Ranaweera wrote:

    > Hi,
    >
    > Any resources to start Cayenne as a JPA provider in a web server
    > like Tomcat or Jetty?
    >
    > Thanks,
    > Lasantha
    >



    This archive was generated by hypermail 2.0.0 : Wed Feb 21 2007 - 09:49:36 EST