[jboss-user] [EJB 3.0] - Persisting POJO entities defined in a different jar

nbhatia do-not-reply at jboss.com
Sun Jul 20 18:37:20 EDT 2008


I have an existing jar file containing POJO entities (no JPA annotations, no persistence.xml). I would like to persist there entities using a new EJB jar file which contains a persistence.xml and a mapping file. Is this possible? I tried it, but I am getting a InvalidMappingException:


  | Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource mappings.xml
  |         at org.hibernate.cfg.Configuration.addResource(Configuration.java:569)
  |         at org.hibernate.ejb.Ejb3Configuration.addClassesToSessionFactory(Ejb3Configuration.java:910)
  |         ... 101 more
  | Caused by: org.hibernate.AnnotationException: Unable to load class defined in XML: samples.estorejpa.domain.Customer
  |         at org.hibernate.cfg.AnnotationConfiguration.add(AnnotationConfiguration.java:592)
  |         at org.hibernate.cfg.AnnotationConfiguration.addInputStream(AnnotationConfiguration.java:674)
  |         at org.hibernate.cfg.Configuration.addResource(Configuration.java:566)
  |         ... 102 more
  | Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: samples.estorejpa.domain.Customer
  |         at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
  |         at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
  |         at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
  |         at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
  |         at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
  |         at java.lang.Class.forName0(Native Method)
  |         at java.lang.Class.forName(Class.java:247)
  |         at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:112)
  |         at org.hibernate.reflection.java.JavaXFactory.classForName(JavaXFactory.java:153)
  |         at org.hibernate.cfg.AnnotationConfiguration.add(AnnotationConfiguration.java:589)
  |         ... 104 more
  | 

Here are the relevant files in my ear. estore-common-1.0.jar contains the POJO entities. estore-server-1.0.jar is the EJB jar that contains persistence.xml, mappings.xml and and a stateless session bean called OrderServiceBean. I was hoping that the POJO entity classes would be visible when parsing persistence.xml because they are in the classpath, but that does not seem to be true.


  | estore-1.0.ear
  | |---estore-common-1.0.jar
  | |---estore-server-1.0.jar
  | |   |---mappings.xml
  | |   |---META-INF
  | |   |   |---ejb-jar.xml
  | |   |   |---jboss.xml
  | |   |   `---persistence.xml
  | |   `---samples
  | |       `---estorejpa
  | |           `---service
  | |               |---OrderService.class
  | |               `---OrderServiceBean.class
  | `---META-INF
  |         application.xml
  | 

Here's my persistence.xml:


  | <persistence>
  |     <persistence-unit name="EstorePersistenceUnit">
  |         <jta-data-source>java:/estore</jta-data-source>
  |         <mapping-file>mappings.xml</mapping-file>
  |         <properties>
  |             <property name="jboss.entity.manager.factory.jndi.name" value="java:/persistence-units/EstorePersistenceUnit"/>
  |         </properties>
  |     </persistence-unit>
  | </persistence>
  | 

Here's my mappings.xml:


  | <entity-mappings>
  |     <description>eStore JPA Mappings</description>
  |     <package>samples.estorejpa.domain</package>
  |     <entity class="samples.estorejpa.domain.Customer" name="Customer">
  |         <table name="CUSTOMER"/>
  |         <attributes>
  |             <id name="id">
  |                 <generated-value/>
  |             </id>
  |             <basic name="version"/>
  |             <basic name="name"/>
  |         </attributes>
  |     </entity>
  |     ...
  | </entity-mappings>
  | 

Any help would be much appreciated.

Thanks.
Naresh

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4165541#4165541

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4165541



More information about the jboss-user mailing list