[jboss-user] [JBoss Seam] - Re: 2 jars , no inject

mzeijen do-not-reply at jboss.com
Tue Aug 29 02:57:30 EDT 2006


I just read from a different topic (http://www.jboss.com/index.html?module=bb&op=viewtopic&t=89223)  that I started that it isn't possible to resolve entity beans over JNDI but that you have to add them to each ear project.

I already got this working but there is a trapdoor. Each ejb jar that needs to be able to work with the entity-manager needs a persistence.xml. The problem lies in the ejb jar that doesn't house the entity classes but only uses them. In the persistence.xml in this ejb you need to define, next to the datasource, which classes are entity classes. Normally the easiest way to do this is as following:


  | <?xml version="1.0" encoding="UTF-8"?>
  | <persistence xmlns="http://java.sun.com/xml/ns/persistence"
  | 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  | 	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  | 	version="1.0">
  | 
  | 	<persistence-unit name="MyEntityManager" transaction-type="JTA">
  | 		<jta-data-source>java:/MyDS</jta-data-source>
  | 		<jar-file>../dataEJB.jar</jar-file>
  | 		<properties></properties>
  | 	</persistence-unit>
  | 	
  | </persistence>
  | 

The jar-file property links to the jar file where the entity beans can be found. The entityManager should scan this jar for the entities and the problems is solved. But because of a bug in the jboss implementation of ejb3 the path to the jar file isn't resolved correctly.

Luckily there is another way to define the entity classes. It isn't pretty but the only solution until they fix the bug (I hope they will do that soon). By using the class tag you can define each class that are entity classes:


  | 
  | <?xml version="1.0" encoding="UTF-8"?>
  | <persistence xmlns="http://java.sun.com/xml/ns/persistence"
  | 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  | 	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  | 	version="1.0">
  | 
  | 	<persistence-unit name="MyEntityManager" transaction-type="JTA">
  | 		<jta-data-source>java:/MyDS</jta-data-source>
  | 		<class>my.package.User</class>
  | 		<class>my.package.SomeOtherEntity</class>
  | 		<properties></properties>
  | 	</persistence-unit>
  | 	
  | </persistence>
  | 
  | 

I hope this prevents hours of work ;).

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

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



More information about the jboss-user mailing list