|Re: Can I create database sessions from an external file? [message #804498 is a reply to message #804374]
||Wed, 22 February 2012 17:44
| Dean Schulze
Registered: February 2012
The JavaDocs for createEntityManagerFactory() are inadequate and confusing. The 3 createEntityManagerFactory() methods all take a persistenceunit name, but the Javadocs don't give you a clue what can go in the properties or that the properties override what is in persistence.xml.
After checking the JPA 2.0 spec and the EclipseLink docs I've posted what I've learned at stackoverflow (copied below since this forum software won't allow me to include the URL).
You have to know what to put into the properties map and the Javadocs don't help at all. The Javadocs for createEntityManagerFactory() just suck.
======= From my post at StackOverflow ==================================
The confusing thing about using properties to dynamically create EntityManagers is that there are three createEntityManagerFactory() methods in JPA and all 3 take a persistenceunit name. I didn't realize that the properties override the persistenceunit name until I checked the JPA 2.0 spec. Section 9.4.3 says that the properties override the values given in the persistence.xml. It also shows what the standard property names are.
(The JavaDocs don't tell you what can go into the properties and they don't say that the properties override what is in persistence.xml. Another example where JavaDocs suck.)
Your example uses property names like "JDBC_URL" that aren't in the Java EE 6 API Javadocs. The JPA spec explains that vendor specific property names can be used in addition to the standard properties. The EclipseLink docs show what property names that implementation supports via the non-standard PersistenceUnitProperties.
So in order to have dynamic EntityManagers it is necessary to use vendor specific properties, so dynamic entity managers aren't portable. I guess you can't have everything.
One case where dynamic EntityManagers would be portable is through the use of the standard javax.persistence.jtaDataSource property. You would have to add the data source to your Java EE container, but that is as dynamic as you can be when running in a container. In Java SE it doesn't look like there are any portable, dynamic options.
The JavaDocs need to do a much better job of explaining how properties work with the createEntityManagerFactory() methods.
[Updated on: Wed, 22 February 2012 17:46]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.17502 seconds