Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate with Application server connection pool

 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have successfully tested using hibernate in my application.

However now i need to be able to use hibernate in such a way that the Application server takes care of handling database connections from it's connection pool. Which means like in Entity beans programmer should be able to use db connections without having to worry about open/close connections. So he could focus only on business logic of the application

ideally the HQL must be executed by using an availbale connection from application server's pooled connection, by the application server.

Is this possible? :roll:

please help.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. Check your app server docs for exact details, but typically you'd just set up your data source to use connection pooling and have hibernate look it up through JNDI.
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Paul.
I have created the datasource to use connection pooling. (I am using the Sun Application server Platform Ed. 8.). What i don't understand is how to make Hibernate look it up. Do i have to do some changes in Hibernate.Properties file?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

add that to you hibernate.properties file. Obviously change it to reflect how you've named your DS in JNDI.
[ June 28, 2004: Message edited by: Paul Sturrock ]
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I edited the hibernate.properties. Now my application refers to the db with using the JNDI to the application server datasource and it queries perfectly.

But does that mean still i have to open/close connection when i have to i.e. add a record to the database?

Well in Entity beans if i call the create method of the bean it straigtaway adds the record without having to worry about open/close connection. Does Hibernate provide that sort of thing?

thanks for the help
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But does that mean still i have to open/close connection when i have to i.e. add a record to the database?

Ehm, you can't do this through Hibernate - it doesn't have a Connection object you can access. With Hibernate you would open a Session, do some DB stuff, then flush and close it. What Hibernate does with connections is entirely up to Hibernate and your connection pool provider.
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i need help with transaction mgt. strategy. How do i achieve declarative transaction demarcation?

I need my app server to take care of transactions. In that case i will have to specify the demarcation in the deployment descriptor of my EJB component and that's fine. Do i have to do any changes in my Hibernate.properties file too?

Ideally i need the HQL queries to be executed without wrapping it in a programmatically specified transaction (session.beginTransaction(),transaction.commit()).

thanks
 
Shanika Weerapperuma
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think i figured it out.

I simply removed the begin__ and commit statements and before closing the session i do a flush() on it. And also in my hibernate.properties file i no more use the
hibernate.transaction.factory_class net.sf.hibernate.transaction.JTATransactionFactory


The records get added to the database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic