How can I merge / extend persistence units from different JARs?

不打扰是莪最后的温柔 提交于 2019-11-30 18:58:50

First, here is a link on Dynamic-JPA they offer a way to update entities dynamically. I would explore this option first.


Here is another link (PDF) from OSGi there are a few top level diagrams dealing with persistence and the EntityManagerFactory that may be useful.


an interesting approach but may be unrelated

Here is a link on creating persistence units programmaticly without using a persistence.xml file (which you can't really do, but the answers offer some insight to the problem). philk offers a suggestion on how to remove the provider from the persistence.xml file. If you follow this method, you may be able to combine your entities into a specific persistence unit.

"Well in the good old days of Hibernate I could just create a session and add my classes to it on the fly. Seems that never made it into SUNs JPA specs. However I have completely removed the provider from the persistence.xml and hand it to EL using the properties of the EMF. This seems to work ok. The only thing left in the persistence.xml is the spec of the classes. I guess it would not be too hard to expose the method that parses the classname in EL and creates the ClassDescriptor for it as a public method of the EL JPA Provider. "


Finally, we come to the hackish solution, doing has already been suggested, simply edit your persistence.xml files after the fact. I believe this would work (although, I haven't tried it) but it is definitely an option.

I have a setup where a WAR file contains the persistence.xml file. The solution already described here should be usable for JAR's, WAR's and EAR's. JPA 2.0: Adding entity classes to PersistenceUnit *from different jar* automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!