tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <>
Subject Re: Alternatives to specifying persistence provider in component jars?
Date Thu, 13 Dec 2007 04:38:26 GMT
Hi Alex,

We actually do have to do quite a bit of linking and other work to  
support JPA, so you definitely came to the right list.  I'm ripping  
that code up right now in fact.

While you do have to have a persistence.xml file for your application,  
*some* of the values in a persistence.xml can be supplied via system  
properties and left out of your persistence.xml.

Namely the following:

Note that the javax.persistence.provider will default to OpenJPA (i.e.  
org.apache.openjpa.persistence.PersistenceProviderImpl).  While that's  
nice, it doesn't allow you to pass the vendor specific properties,  
namely the truly amazing "openjpa.jdbc.SynchronizeMappings" that will  
basically allow you to squeak by not having to create or drop tables.

We don't yet have the ability to fully define persistence units at the  
openejb.xml level, but that definitely is a feature I've thought of  

Along the lines of hooking your application up to persistence units  
defined in a persistence.xml, I added some great code for the upcoming  
beta 2 that performs some pretty bullet proof validation of your app.   
Some sample validation messages you might see in beta 2 are:

Mistaken use of @PersistenceUnit on an EntityManager reference.  Use  
@PersistenceContext for ref "org.superbiz.injection.jpa.MoviesImpl/ 

Mistaken use of @Resource on an EntityManager reference.  Use  
@PersistenceContext for ref "org.superbiz.injection.jpa.MoviesImpl/ 

Persistence unit not found for  
@PersistenceContext(name="entityManager", unitName="movie-unnit").   
Available units [movie-unit]

We also have a new example for showing dependency injection of JPA  
EntityManagers.  It's fun to run it and attempt to break the app by  
adding, changing, or removing persistence units or references to them.  
If you find a way that we don't check for, I'll by you a book on  
amazon.  And as usual, all validation come in all-at-once "compiler"  
format, so it should be possible to spot all your mistakes in one go  
avoiding countless "small fix, compile, redeploy, fail, repeat" cycles.

The new example:


On Dec 12, 2007, at 7:29 PM, Alexander Saint Croix wrote:

> Hello,
> I'm working on an application that at the moment includes a single
> (proof-of-concept) entity bean in my main web application WAR, and  
> also
> large number of entity beans which are JAR'd in the WEB-INF/lib.
> Knowing that the persistence management is all outboard and not  
> contained
> inside of OpenEJB, perhaps you guys could help me with a matter of
> configuration anyway.
> I wonder whether there is any way for me to NOT include the  
> <provider> and
> <properties> elements defining the persistence provider  
> implementation,
> connection URL, connection driver name, username and password in the
> persistence.xml file for my entity/POJO jar (the one inside of WEB- 
> INF/lib),
> but rather configure that specific portion of the persistence.xml file
> inside of the context of the application that is using these beans?   
> It
> doesn't seem to be any of the POJO JAR's business what type of  
> persistence
> provider is being used to persist its contents.
> I've attached an example of the <provider> and <properties> elements  
> I wish
> to exclude below.  I want to define classes but not persistence  
> provider
> information in the entity JARs, and define the persistence provider  
> for
> these persistence-units once at the container level.  Is this  
> possible, and
> if so, how might I accomplish that separation with OpenEJB?
> Regards,
> --
> Alexander R. Saint Croix
> <persistence xmlns=""  
> version="1.0">
>    <persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
>        <provider>
>            org.apache.openjpa.persistence.PersistenceProviderImpl
>        </provider>
>        <class>org.eremite.SomeBeanInThisJar</class>
>        <properties>
>            <property name="openjpa.jdbc.SynchronizeMappings"
>                      value="buildSchema"/>
>            <property name="openjpa.ConnectionURL"
>                      value="jdbc:mysql://localhost/corm"/>
>            <property name="openjpa.ConnectionDriverName"
>                      value="com.mysql.jdbc.Driver"/>
>            <property name="openjpa.ConnectionUserName"
>                      value="username"/>
>            <property name="openjpa.ConnectionPassword"
>                      value="password"/>
>        </properties>
>    </persistence-unit>
> </persistence>

View raw message