0

we've a persistence archive containing only Entities and the persistence.xml. And we've an ejb module containing the ejb stuff.

Now for a specific use case we need to add an EntityListener which has access to some EJBs in the service layer.

The ejb module depends on the persistence module. However to declare the listener in the Entity the persistence module needs to know about the class in the ejb module. A cyclic dependency is not possible and having a third module containing only the JPA listener leads to cyclic dependencies as well.

So the only option I see is to merge the ejb module and the persistence archive into a single module. However that way we loose the flexibility to use the persistence archive in another application to connect to the remote interfaces without carrying the whole ejb jar's content.

Any ideas on how to solve this and stay modular (separate ejb and persistence modules?).

We're talking about a JEE7 application.

StanislavL
  • 56,971
  • 9
  • 68
  • 98
Thomas Becker
  • 934
  • 8
  • 16

2 Answers2

1

You could move the persistence.xml from your JPA project to your EJB project and then use the <jar-file>packedEntity.jar</jar-file> XML element. Check this answer.

Community
  • 1
  • 1
V G
  • 18,822
  • 6
  • 51
  • 89
0

One idea is to use your Source-Control-Management (git/svn/cvs) to import the entity package in your EJB project (+the persistence.xml file). This way, you have more flexibility on what/how you define them. In SVN you have svn:externals. For git check out this answer.

Community
  • 1
  • 1
V G
  • 18,822
  • 6
  • 51
  • 89
  • Not sure you got the question right. I've basically four maven modules: persistence (containing entities), interfaces, web (the war) and ejb. Problem is that to use entity-listeners via annotation, this separation doesn't work as the Entity needs to know about the listener. And the listener needs some beans from the ejb package. – Thomas Becker Apr 29 '15 at 14:09
  • I am not sure if it is possible to define the entity-listener outside your entity project. Given that, my idea was to get rid of that maven project with entities, and instead to integrate only the needed source code (Java entities) per svn:externals in your EJB project. – V G Apr 29 '15 at 14:34