aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate with Application server connection pool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate with Application server connection pool" Watch "Hibernate with Application server connection pool" New topic
Author

Hibernate with Application server connection pool

Shanika Weerapperuma
Greenhorn

Joined: Jun 28, 2004
Posts: 26
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Shanika Weerapperuma
Greenhorn

Joined: Jun 28, 2004
Posts: 26
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

Joined: Apr 14, 2004
Posts: 10336


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

Joined: Jun 28, 2004
Posts: 26
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

Joined: Apr 14, 2004
Posts: 10336


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

Joined: Jun 28, 2004
Posts: 26
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

Joined: Jun 28, 2004
Posts: 26
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate with Application server connection pool