-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Configuring EntityManager with User supplied connection
PostPosted: Fri Jul 06, 2007 6:42 am 
Newbie

Joined: Fri Jul 06, 2007 5:13 am
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 11, 2007 12:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Why do you need to avoid connection pooling, this is really crazy.
If you want to do that you could write your own connection pool that actually does not pool.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 5:18 am 
Newbie

Joined: Fri Jul 06, 2007 5:13 am
Posts: 3
We cannot implement Connection Pooling according to our database architecture.

The question is if it is possible to use Hibernate when you are not interested in Connection Pooling. An ideal case would be to instantiate EntityManager with the help of a Connection and use it for the user session/transaction and clear it once the user logs out.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 12, 2007 8:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no.
Unless once again you write a connection provider that will get your connection from somewhere.

But expect some limitations, some operations require concurrent 2 DB connections to be handled properly.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.