-->
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.  [ 10 posts ] 
Author Message
 Post subject: Using stanalone application to test hibernate objects
PostPosted: Wed Apr 13, 2005 10:20 pm 
Newbie

Joined: Wed Apr 13, 2005 2:43 am
Posts: 9
hi everyone,

how use a standalone application to test hibernate objets?

also, how to you test your hibernate objects?

Regards,
Paul


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 4:52 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
Junit

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 7:45 am 
Newbie

Joined: Wed Apr 13, 2005 2:43 am
Posts: 9
question is that all hibernate objects need to be deployed on application server. How can JUnit connect to objects on the server side?

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 8:14 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
paulur wrote:
question is that all hibernate objects need to be deployed on application server. How can JUnit connect to objects on the server side?

Paul


What is the specific problem you are encountering ?

If you are writing code that uses hibernate to access the database, then test that code via a Junit test from the command line or IDE or whatever.

If you have hibernate code embedded in your server side code then test your server side code in exaclty the same manner as if you were coding manual SQL, whatever that is.

It almost sounds as if you are mixing business logic and persitence code layers.

THe persistence layer should be completely separate from the business logic layer, and should be capabable of being tested in a completely stand alone environment e.g. Junit test suites

I think this is an architecture question, not a hibernate question.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 8:30 am 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Not sure if this fits your development model, but we are using Hibernate through Spring and it is working very very well. Configuration of the Hibernate session works almost the same way in JUnit as it does in our web container. Spring provides great support for both Hibernate (Session and Transaction management; Exception hierarchy) and JUnit (Transactional test cases, etc).

HTH,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 10:17 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
cbredesen wrote:
Not sure if this fits your development model, but we are using Hibernate through Spring and it is working very very well. Configuration of the Hibernate session works almost the same way in JUnit as it does in our web container. Spring provides great support for both Hibernate (Session and Transaction management; Exception hierarchy) and JUnit (Transactional test cases, etc).

HTH,

Chris


We use Spring as well and the only thing different that we do for tests is to have a different version of the Spring applicationContext.xml file, with the test version using a JDBC URL to get the connections, as opposed to the live one using a datasource.

This jsut allows us to test the hibernate coe without having the app server running.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 2:21 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Paul Newport, cbredesen,

are you using the AOP Interceptor or the Hibernate Template...? Just wanna know the best of two.

Thanks.

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 2:35 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
We extend Spring's base Hibernate DAO, which provides the template for your calls into Hibernate (either via Callback or convenience methods). Our transactions are managed by the TransactionInterceptor (AOP) around the business classes and we also use the OpenSessionInViewFilter to defer the session close till the end of our servlet request.

The OSIV functionality is also present in our JUnit integration tests, but I had to do a little coding to get that to work.

If you are asking whether I'm doing programmatic or declarative transaction management, we are using declarative. We never manually begin or commit/rollback transactions. Happy happy.

HTH,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 2:50 pm 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi Chris,

what need to be extends in the spring base Hibernate DAO?

Thanks.

Etienne.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 14, 2005 3:05 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Everything you need to know is here:

http://hibernate.bluemars.net/110.html

To answer your specific question, you simply make all your DAO's extend HibernateDaoSupport, and then configure those DAO's in Spring's applicationContext to have a reference to the configured Hibernate session (also configured very easily in Spring) and you're good to go. All the Hibernate functionality is available to your DAO through getHibernateTemplate(). You can use either the convenience methods (common CRUD stuff) or call execute() and implement a HibernateCallback() which gives you full access to Hibernate session.

Enjoy!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 10 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.