Hello all,
According to the architecture of our application we are required to make normal direct JDBC connections(no connection pooling).
In this context I tested Hibernate using SessionFactory,Session objects successfully since I was able to pass on my java.sql.Connection object to the Session.
Now I switched to the EntityManagerFactory,EntityManager approach.I need some verification for my architecture. I plan to use one EntityManagerFactory for the application and for all users and create one EntityManager per user.
Is it possible to give EntityManager a connection??
I have tried 2 approaches,
1. Approach
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyPersistenceUnit");
Map myProperties = new HashMap();
myProperties.put("hibernate.connection.driver_class","oracle.jdbc.driver.OracleDriver");
myProperties.put("hibernate.connection.url","myurl");
myProperties.put("hibernate.connection.username","myusername");
myProperties.put("hibernate.connection.password","mypwd");
EntityManager em = emf.createEntityManager(myProperties);
But this approach chokes when I try to make a transaction...
- Servlet.service() for servlet ConnectionManager threw exception
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)
-------------------
2. Approach
Code:
//added this to the myproperties above
myProperties.put("hibernate.session_factory_name", emf);
EntityManager em = new EntityManagerImpl(null,EXTENDED,RESOURCE_LOCAL,new Boolean(true),myProperties);
Even this approach gives this exception...
java.lang.NullPointerException
at org.hibernate.ejb.EntityManagerImpl.getRawSession(EntityManagerImpl.java:48)
at org.hibernate.ejb.EntityManagerImpl.getSession(EntityManagerImpl.java:43)
at org.hibernate.ejb.TransactionImpl.getSession(TransactionImpl.java:28)
at org.hibernate.ejb.TransactionImpl.begin(TransactionImpl.java:38)
It would be great if someone can point out the error or correct the approach,
best wishes
Jan