0

I am using JBoss 4.2.3 application server.

I have an EAR that currently contains 2 EJB (EJB 3) jars.

In the main EJB jar I have persistence.xml file with the data source configurations.

From the secondary EJB jar file I can successfully call the the EntityManager and read\write entities that are defined in the main EJB jar that contains the persistence.xml

If I try to put an entity in the secondary EJB jar module and then persist it via the EntityManager that uses the persistence unit from the main EJB I get an exception:

Caused by: org.hibernate.hql.ast.QuerySyntaxException: [ENTITY-CLASS-NAME] is not mapped

The solution I found is to create another persistence.xml in the secondary EJB module and change the persistence unit name.

I am not sure whether what I tried to do is correct? Can you please contribute whether I can have a way to share the same persistence.xml withing multiple EJB modules in the EAR (in a way I can have entities in both EJB modules)?

dgw
  • 13,418
  • 11
  • 56
  • 54
Eli Avital
  • 21
  • 1
  • 3

1 Answers1

0

Put the persistence.xml and entities into a JAR in the top-level lib/ directory of the EAR. This should allow the persistence units to be used by all modules in the EAR.

Brett Kail
  • 33,593
  • 2
  • 85
  • 90
  • Hi, Thank you for your answer. But, in that case the entities are still shared, I want to separate the entities to be relevant only for a specific EJB project I am using. – Eli Avital Apr 01 '12 at 08:14
  • What I did is to add persistence.xml to the specific EJB project I want to also be able to see the entities. Then I leave it mostly blank, but use the tag to point at my other EJB, e.g. Other-ejb.jar – Torbjørn Kristoffersen Feb 11 '13 at 13:11
  • @T.K. I know it's been a while but can you expound on your comment? Would the `Other-ejb.jar` be listed in application.xml as an ejb module in that case or just a java module? – StormeHawke Nov 08 '13 at 15:35