PGK
PGK

Reputation: 141

eclipselink without persistence.xml and multiple persistence.xml

Hi I am trying to develop a JPA application using EclipseLink. I am trying to create it without persistence.xml or at least the Persistence Unit will be created during run time. So I have an empty (or rather dummy) persistence.xml to start with. I looked at this post eclipselink without persistence.xml but after debugging I noticed, EL forces to declare at least PU name and all other parameters can be set (including provider) during runtime. Is there a way, PU can be created only during runtime? I am trying to create multiple PU based on number of categories in application which is known only during run time.

currently I am overwriting all other parameters except name (which I can't overwrite) and create a EM factory per category.

Thanks in advance,

Gopi

Upvotes: 1

Views: 1977

Answers (1)

James
James

Reputation: 18379

JPA defines a createContainerEntityManagerFactory(PersistenceUnitInfo info, Map properties) in PersistenceProvider that does not require a persistence.xml (the container is responsible for processing it). You could probably call this directly on the EclipseLink PersistenceProvider, and pass your own PersistenceUnitInfo.

You may want to look into EclipseLink multitenancy support,

http://www.eclipse.org/eclipselink/documentation/2.4/solutions/multitenancy.htm#CHDBJCJA

Upvotes: 2

Related Questions