문제

I try to develop a Java Plugin application using the Java plugin framework. All plugins will have acces to a uniq database using JPA (with Eclipselink).

But each plugin will have there own Entities.

So I could not declare all Entities in one unique file persitence.xml in the core plugin.

The question is: is it possible to declare Entity class on the fly when declaring the EntityManagerFactory? I am already using a Map to get connection string and user/password from user configuration file.

Is there a way to do the same with Entities ?

Map<String, String> p = new HashMap<String, String>();
p.put("javax.persistence.jdbc.url", dns);
p.put("javax.persistence.jdbc.driver", "com.mysql.jdbc.Driver");
p.put("javax.persistence.jdbc.user", config.getProperty("com.cjrf.xbmo.db.username", ""));
p.put("javax.persistence.jdbc.password", config.getProperty("com.cjrf.xbmo.db.password", ""));
entityManagerFactory = Persistence.createEntityManagerFactory("mediamanager", p);

Thanks for your help.

도움이 되었습니까?

해결책

If your only concern is not do declare the class files in the persistence.xml then you can use auto detect funcionality.

For eclipselink add this to persistence.xml

<exclude-unlisted-classes>false</exclude-unlisted-classes>

Now all annotation mapped with @Entity will be scanned automatically.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top