You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by Quintin Beukes <qu...@last.za.net> on 2009/09/21 11:59:00 UTC

Multiple Persistence Unit foreign key references

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:
Apache OpenEJB 3.1.2-SNAPSHOT    build: 20090827-09:05
http://openejb.apache.org/
INFO - openejb.home = /home/quintin/dev/kms/VDS/VDS-lamps-ejb
INFO - openejb.base = /home/quintin/dev/kms/VDS/VDS-lamps-ejb
INFO - Configuring Service(id=Default Security Service,
type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=jdbc_kmsPool, type=Resource,
provider-id=Default JDBC Database)
INFO - Found EjbModule in classpath:
/home/quintin/.m2/repository/net/kunye/KMS-Personnel-ejb/1.0/KMS-Personnel-ejb-1.0.jar
INFO - Found EjbModule in classpath:
/home/quintin/.m2/repository/net/kunye/KMSPlatform-ejb/1.0/KMSPlatform-ejb-1.0.jar
INFO - Found EjbModule in classpath:
/home/quintin/.m2/repository/net/kunye/VDS-ejb/1.0/VDS-ejb-1.0.jar
INFO - Found ClientModule in classpath:
/home/quintin/.m2/repository/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar
INFO - Found EjbModule in classpath:
/home/quintin/dev/kms/VDS/VDS-lamps-ejb/target/classes
INFO - Found ClientModule in classpath:
/home/quintin/.m2/repository/javassist/javassist/3.4.GA/javassist-3.4.GA.jar
INFO - Found EjbModule in classpath:
/home/quintin/.m2/repository/net/kunye/UnitTesting/1.0/UnitTesting-1.0.jar
INFO - Beginning load:
/home/quintin/.m2/repository/net/kunye/KMS-Personnel-ejb/1.0/KMS-Personnel-ejb-1.0.jar
INFO - Beginning load:
/home/quintin/.m2/repository/net/kunye/KMSPlatform-ejb/1.0/KMSPlatform-ejb-1.0.jar
INFO - Beginning load:
/home/quintin/.m2/repository/net/kunye/VDS-ejb/1.0/VDS-ejb-1.0.jar
INFO - Beginning load:
/home/quintin/.m2/repository/org/hibernate/hibernate-core/3.3.2.GA/hibernate-core-3.3.2.GA.jar
INFO - Beginning load: /home/quintin/dev/kms/VDS/VDS-lamps-ejb/target/classes
INFO - Beginning load:
/home/quintin/.m2/repository/javassist/javassist/3.4.GA/javassist-3.4.GA.jar
INFO - Beginning load:
/home/quintin/.m2/repository/net/kunye/UnitTesting/1.0/UnitTesting-1.0.jar
INFO - Configuring enterprise application: classpath.ear
INFO - Configuring Service(id=Default Stateless Container,
type=Container, provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean PersonnelBean:
Container(type=STATELESS, id=Default Stateless Container)
INFO - Configuring PersistenceUnit(name=KMS-Personnel-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Auto-creating a Resource with id 'jdbc_kmsPoolNonJta' of type
'DataSource for 'KMS-Personnel-PU'.
INFO - Configuring Service(id=jdbc_kmsPoolNonJta, type=Resource,
provider-id=jdbc_kmsPool)
INFO - Adjusting PersistenceUnit KMS-Personnel-PU <jta-data-source> to
Resource ID 'jdbc_kmsPool' from 'jdbc/kmsPool'
INFO - Adjusting PersistenceUnit KMS-Personnel-PU
<non-jta-data-source> to Resource ID 'jdbc_kmsPoolNonJta' from 'null'
INFO - Configuring PersistenceUnit(name=KMSPlatform-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Adjusting PersistenceUnit KMSPlatform-PU <jta-data-source> to
Resource ID 'jdbc_kmsPool' from 'jdbc/kmsPool'
INFO - Adjusting PersistenceUnit KMSPlatform-PU <non-jta-data-source>
to Resource ID 'jdbc_kmsPoolNonJta' from 'null'
INFO - Configuring PersistenceUnit(name=VDS-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Adjusting PersistenceUnit VDS-PU <jta-data-source> to Resource
ID 'jdbc_kmsPool' from 'jdbc/kmsPool'
INFO - Adjusting PersistenceUnit VDS-PU <non-jta-data-source> to
Resource ID 'jdbc_kmsPoolNonJta' from 'null'
INFO - Configuring PersistenceUnit(name=VDS-lamps-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Adjusting PersistenceUnit VDS-lamps-PU <jta-data-source> to
Resource ID 'jdbc_kmsPool' from 'jdbc/kmsPool'
INFO - Adjusting PersistenceUnit VDS-lamps-PU <non-jta-data-source> to
Resource ID 'jdbc_kmsPoolNonJta' from 'null'
INFO - Enterprise application "classpath.ear" loaded.
INFO - Assembling app: classpath.ear
INFO - PersistenceUnit(name=KMS-Personnel-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - PersistenceUnit(name=KMSPlatform-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - PersistenceUnit(name=VDS-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - PersistenceUnit(name=VDS-lamps-PU,
provider=org.hibernate.ejb.HibernatePersistence)
INFO - Undeploying app: classpath.ear
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
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:665)
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:449)
        at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:367)
        at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:279)
        at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:137)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:286)
        at org.apache.openejb.OpenEJB.init(OpenEJB.java:265)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.openejb.loader.OpenEJBInstance.init(OpenEJBInstance.java:36)
        at org.apache.openejb.client.LocalInitialContextFactory.init(LocalInitialContextFactory.java:71)
        at org.apache.openejb.client.LocalInitialContextFactory.init(LocalInitialContextFactory.java:53)
        at org.apache.openejb.client.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:42)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:197)
        at net.kunye.platform.testing.LocalTestFramework.<init>(LocalTestFramework.java:77)
        at net.kunye.vds.lamps.LampBeanTest.<clinit>(LampBeanTest.java:33)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
        at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
        at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
        at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
Caused by: org.apache.openejb.OpenEJBException:
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
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:494)
        ... 40 more
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne
on net.kunye.vds.lamps.LampAssignment.employee references an unknown
entity: net.kunye.personnel.Employee
        at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:81)
        at org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
        at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
        at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
        at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1162)
        at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1226)
        at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:173)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:854)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:425)
        at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:131)
        at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:184)
        at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:489)
        ... 40 more
Tests run: 29, Failures: 0, Errors: 27, Skipped: 0, Time elapsed:
2.546 sec <<< FAILURE!

How can I get them to notice each other?

Quintin Beukes

Re: Multiple Persistence Unit foreign key references

Posted by Quintin Beukes <qu...@skywalk.co.za>.
Thanks for the doc-link and the explanation.

I did actually use the <class> elements eventually, and it did the trick.

Quintin Beukes



On Wed, Sep 23, 2009 at 12:19 PM, David Blevins <da...@visi.com> wrote:
>
> 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
>
>

Re: Multiple Persistence Unit foreign key references

Posted by David Blevins <da...@visi.com>.
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