0

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.

fluminis
  • 3,575
  • 4
  • 34
  • 47

2 Answers2

1

This might help:

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

Mihai Toader
  • 12,041
  • 1
  • 29
  • 33
0

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.

Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
uncaught_exceptions
  • 21,712
  • 4
  • 41
  • 48