开发者

How to declare Entities on the fly?

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 Enti开发者_如何转开发ties 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.


This might help:

http://www.dynamicjava.org/projects/dynamic-jpa


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜