[hibernate-issues] [Hibernate-JIRA] Created: (JPA-25) Hibernate EntityManager does not allow changing database connection information after EntityManagerFactory creation
Monique Louise de Barros Monteiro (JIRA)
noreply at atlassian.com
Fri Dec 9 11:23:22 EST 2011
Hibernate EntityManager does not allow changing database connection information after EntityManagerFactory creation
-------------------------------------------------------------------------------------------------------------------
Key: JPA-25
URL: http://opensource.atlassian.com/projects/hibernate/browse/JPA-25
Project: Java Persistence API
Issue Type: Bug
Affects Versions: 1.0.0
Environment: hibernate-entity-manager-3.2.1.ga, hibernate-3.2.4.sp1, Oracle database
Reporter: Monique Louise de Barros Monteiro
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 org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:30)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:50)
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.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list