-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @ManyToOne between entities in two different jars
PostPosted: Tue Sep 02, 2008 3:45 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
Hello,

I use Hibernate as JPA implementation and I need to create a @ManyToOne link between two entities in two different jars. But I can't find the way to do this. On server startup (OpenEJB used for unit tests in a Maven project) I have the following exception :

Code:
org.apache.openejb.OpenEJBException: createApplication.failed [C:\Documents\t4-core-commons\core\target\classes]: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on t4.core.commons.reasonInstruction.internal.Reason.process references an unknown entity: t4.core.utils.process.internal.Process: @OneToOne or @ManyToOne on t4.core.commons.reasonInstruction.internal.Reason.process references an unknown entity: t4.core.utils.process.internal.Process
   at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:592)
   at org.apache.openejb.assembler.classic.Assembler.buildContainerSystem(Assembler.java:338)
   at org.apache.openejb.assembler.classic.Assembler.build(Assembler.java:250)
   at org.apache.openejb.OpenEJB$Instance.<init>(OpenEJB.java:149)
   at org.apache.openejb.OpenEJB.init(OpenEJB.java:288)
   at org.apache.openejb.OpenEJB.init(OpenEJB.java:267)
   at t4.core.commons.test.OpenEjbBootstrap.startAndDeployResources(OpenEjbBootstrap.java:22)
   at t4.core.commons.test.OpenEjbSeamTest.startJbossEmbeddedIfNecessary(OpenEjbSeamTest.java:59)
   at org.jboss.seam.mock.AbstractSeamTest.startSeam(AbstractSeamTest.java:914)
   at t4.core.commons.test.OpenEjbSeamTest.startSeam(OpenEjbSeamTest.java:35)
   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:585)
   at org.testng.internal.MethodHelper.invokeMethod(MethodHelper.java:580)
   at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:398)
   at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:145)
   at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:82)
   at org.testng.SuiteRunner.privateRun(SuiteRunner.java:262)
   at org.testng.SuiteRunner.run(SuiteRunner.java:191)
   at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:808)
   at org.testng.TestNG.runSuitesLocally(TestNG.java:776)
   at org.testng.TestNG.run(TestNG.java:701)
   at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:77)
   at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:92)
   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:585)
   at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:334)
   at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:980)
Caused by: org.apache.openejb.OpenEJBException: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on t4.core.commons.reasonInstruction.internal.Reason.process references an unknown entity: t4.core.utils.process.internal.Process: @OneToOne or @ManyToOne on t4.core.commons.reasonInstruction.internal.Reason.process references an unknown entity: t4.core.utils.process.internal.Process
   at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:459)
   ... 31 more
Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on t4.core.commons.reasonInstruction.internal.Reason.process references an unknown entity: t4.core.utils.process.internal.Process
   at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:56)
   at org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:428)
   at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
   at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
   at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1233)
   at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:154)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:869)
   at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:407)
   at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
   at org.apache.openejb.assembler.classic.PersistenceBuilder.createEntityManagerFactory(PersistenceBuilder.java:183)
   at org.apache.openejb.assembler.classic.Assembler.createApplication(Assembler.java:454)
   ... 31 more


Is it posssible to link JPA entities from different jars ?

Thanks in advance,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 02, 2008 10:00 am 
Beginner
Beginner

Joined: Mon Jan 10, 2005 7:14 am
Posts: 32
I found part of the solution ...

In persistence.xml file you can define a list of additional classes for a persistence unit thanks to class tag. Something like this :

Code:
<persistence-unit name="t4Seam">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <jta-data-source>java:/jdbc/t4Seam</jta-data-source>
   <class>t4.core.utils.process.internal.Process</class>
   <class>t4.core.utils.process.internal.ProcessFeature</class>
   <class>t4.core.utils.process.internal.ProcessSetting</class>
   <class>t4.core.utils.process.internal.ProcessTemplate</class>
   <class>t4.core.utils.right.internal.Role</class>
   <class>t4.core.utils.right.internal.ProcessRight</class>
   <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <property name="hibernate.show_sql" value="false"/>
   </properties>
</persistence-unit>


Then you just have to add the jars containing theses classes to the classpath then it works.

Problem is that it's not a very good solution from a maintenance point of view : if I add new entities to the other jar, I will have to add them by hand in persistence.xml to ensure they are known by my persistence unit. So what I need is to tell Hibernate to scan a jar to retrieve EJB3 entities. For what I understood, this is what jar-file is made for. So I changed my persistence.xml file this way :

Code:
<persistence-unit name="t4Seam">
   <provider>org.hibernate.ejb.HibernatePersistence</provider>
   <jta-data-source>java:/jdbc/t4Seam</jta-data-source>
   <jar-file>t4-core-utils-core-1.0-SNAPSHOT.jar</jar-file>
   <properties>
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <property name="hibernate.show_sql" value="false"/>
   </properties>
</persistence-unit>


But I can't make it work ... It can't find my jar and I have no idea how to solve this. The easiest way would be that Hibernate scans for classpath, but it looks this is not the case : it uses a relative path to retrieve the jar. The problem is that I use Maven to manage depencencies for my project and so I can't access the jar using a relative path ... Anyone has an idea how I could do this ? Is there a way to tell Hibernate that it should look for the jar in classpath ?

Thanks in advance
Merci d'avance ;)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.