tomee-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Blevins <david.blev...@visi.com>
Subject Re: Multiple Persistence Unit foreign key references
Date Wed, 23 Sep 2009 10:19:06 GMT

On Sep 21, 2009, at 2:59 AM, Quintin Beukes wrote:

> Hey,
>
> I have 2 persistence units, one for each module in the system. The
> first has an entity Employee, and the other has an Entity
> LampAssignment. LampAssignment has a @OneToOne on a field:
> private Employee employee;
>
> The JAR containing Employee is KMS-Personnel-ejb-1.0.jar, and it's PU
> is: KMS-Personnel-PU
> The JAR containing LampAssignment is VDS-lamps-ejb, and it's PU is:  
> VDS-lamps-PU
>
> When I try and run this OpenEJB give the following output:
[...]
> ERROR - Application could not be deployed:  classpath.ear
> org.apache.openejb.OpenEJBException: Creating application failed:
> classpath.ear: org.hibernate.AnnotationException: @OneToOne or
> @ManyToOne on net.kunye.vds.lamps.LampAssignment.employee references
> an unknown entity: net.kunye.personnel.Employee: @OneToOne or
> @ManyToOne on net.kunye.vds.lamps.LampAssignment.employee references
> an unknown entity: net.kunye.personnel.Employee
[...]
> How can I get them to notice each other?

No real way to split them into two units like that.  A persistence- 
unit is really the definition of a database cache.  Meaning it's a  
whole view of an entire set of data.  The entity manager instance is  
really your way to pull and push data to and from that cache and by  
definition it can't see data for tables (entities) it doesn't control.

A lot of people want to split up their "units" for build reasons and  
have the entities divided into specific jar files, which is more than  
valid.  But at run time it has to be joined together and defined as  
one persistence-unit if the entities are part of the same relational  
scheme.  You can use the persistence.xml <jar-file> element to pull in  
other jars or use the <class> element to list the classes individually  
and have them count as being in the same unit regardless of which jar  
they may be in.

This doc isn't directly related to your question, but I do find it  
demystifies JPA a bit:

   http://openejb.apache.org/3.0/jpa-concepts.html


-David


Mime
View raw message