I'm trying to migrate my applications from pure Hibernate to JPA.
In my environment, I have a shared library which creates a SessionFactory at startup. Several Web applications use this library and its shared SessionFactory. Also, each Web application uses a particular datasource with a different user/password, although all the applications access the same database. Upon a request, a Session is obtained from a JDBC connection, which is obtained from the application server's managed pool, referenced by the Web application specific JNDI bound datasource.
When I try to migrate this cenary to JPA, in the same way, I need to create an EntityManagerFactory at startup and let each Web application request create a new EntityManager from the same factory but with different database connection information. But I had the following problems:
When the EntityManagerFactory is created with a default connection information and the EntityManager is created through EntityManagerFactory.createEntityManager(map), where map contains a JNDI datasource bound to the "javax.persistence.nonJtaDataSource" property, the same EntityManagerFactory connection information is used, and the datasource connection information is completely ignored.
When the EntityManagerFactory is created without any initial connection information, the following error occurs when an EntityManager is created with datasource information and the underlying JDBC connection needs to accessed:
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at $Proxy116.prepareStatement(Unknown Source)
I studyied Hibernate's source code and I'm afraid Hibernate does not allow changing connection information (user, password, datasource, etc.) after EntityManagerFactory creation.
hibernate-entity-manager-3.2.1.ga, hibernate-3.2.4.sp1, Oracle database