-->
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.  [ 19 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Spring and hibernate 3
PostPosted: Thu Feb 03, 2005 7:37 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
I'm provisionally looking to migrate to hibernate 3 and have come to a grinding halt as Spring does not currently support Hibernate 3 (probably due to the change in package names as much as anything else).

Is there anything in hibernate 3 which makes the use of Spring less attractive ? At the moment the inversion of control features in Spring make coding hibernate very easy (e.g. no need to handle sessions or transactions programmaticlly).

I'd be interested to knwo what other Spring users plan to do as far as migrating to hibernate 3.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 7:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you are in a CMT environment, you should no longer need Spring. AFAICT, people use spring here for four things:

(1) session handling/flushing
(2) transaction management
(3) SQLException mapping
(4) Runtime exceptions model

Well, with hibernate.transaction.flush_before_completion and hibernate.transaction.auto_close_session, (1) is now much, much easier. (2) is handled by CMT. (3) is implemented in the Hibernate Dialect. And Hibernate3 has an unchecked exception model, so (4) is no longer relevant.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 7:50 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
If you are in a CMT environment, you should no longer need Spring..


Thanks for that Gavin. I think I'll convert a small project and see how that goes.

By the way, since we switched to hibernate, we have about 95% les persistence code, and a 6 fold increase in speed when saving our object model.

Brilliant.

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 9:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
If you are in a CMT environment, you should no longer need Spring. AFAICT, people use spring here for four things:

(1) session handling/flushing
(2) transaction management
(3) SQLException mapping
(4) Runtime exceptions model


i can answer for other users who use tomcat for example
(1)- just mix hibernateUtil + servletFilter and you'll have a great session handling, you just have to improve caveatemptor sample to manage both short and long application transaction handling
(2)- no so hard to manage in your controller layer or better in business delegation layer, you just have to abstract transaction
Quote:
(3) is implemented in the Hibernate Dialect. And Hibernate3 has an unchecked exception model, so (4) is no longer relevant

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: converting spring based code to non-spring hibernate 3 code
PostPosted: Thu Feb 03, 2005 9:11 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
If you are in a CMT environment, you should no longer need Spring. AFAICT, people use spring here for four things:

(1) session handling/flushing
(2) transaction management
(3) SQLException mapping
(4) Runtime exceptions model

Well, with hibernate.transaction.flush_before_completion and hibernate.transaction.auto_close_session, (1) is now much, much easier. (2) is handled by CMT. (3) is implemented in the Hibernate Dialect. And Hibernate3 has an unchecked exception model, so (4) is no longer relevant.


Given that I am used to calling hibernate from Spring, I am used to having a Spring applicationContext.xml file.

I've just converted a simple project to use hibernate.cfg.xml

My application code currently is implemented in clsses that extend Spring's HibernateDaoSupport class. So for instance, to save something I do:

getHibernateTemplate().saveOrUpdate(instance);

I am not used to doing anything with sessions or transactions as a result of the reliance on Spring.

Is there any example code of an absolutley minimal Hibernate 3 that does the same as above, running in a CMT ?

Basically I would like to know how to convert my Spring based hibernate 2 methods to plain Hibernate 3.

Any pointers greatly appreciated.

_________________
On the information super B road


Top
 Profile  
 
 Post subject: Re: Spring and hibernate 3
PostPosted: Thu Feb 03, 2005 11:45 am 
Beginner
Beginner

Joined: Thu Jan 20, 2005 3:25 pm
Posts: 22
Paul Newport wrote:
I'd be interested to knwo what other Spring users plan to do as far as migrating to hibernate 3.


I'm currently working on a project with Spring + hibernate 3. I started with Hibernate 2.1 but had too many issues with collections and composite keys so I switched to Hibernate 3 and everything worked out of the box.
You can find classes for hibernate 3 at http://opensource.atlassian.com/projects/spring/browse/SPR-300.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 3:00 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
I am not used to doing anything with sessions or transactions as a result of the reliance on Spring.


If you are in a CMT session bean, if you enable hibernate.transaction.flush_before_completion, hibernate.transaction.auto_close_session and provide hibernate.transaction.flush_before_completion and hibernate.transaction.manager_lookup_class, then there should be not much difference. You don't need to manually handle transactions or do exception handling.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 3:09 pm 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
Quote:
I am not used to doing anything with sessions or transactions as a result of the reliance on Spring.


If you are in a CMT session bean, if you enable hibernate.transaction.flush_before_completion, hibernate.transaction.auto_close_session and provide hibernate.transaction.flush_before_completion and hibernate.transaction.manager_lookup_class, then there should be not much difference. You don't need to manually handle transactions or do exception handling.


OK thanks Gavin, I will try all this out once I get hold of a 1.4 version of H3 (source forge's cvs seems to be unavailable at the moment).

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 03, 2005 3:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
just run "ant jar" in your hibernate 3.0beta4 install dir.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:53 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
just run "ant jar" in your hibernate 3.0beta4 install dir.


All up and working now thanks. I've noticed some System.out.println's in teh code, will this go in the RC ?

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Paul Newport wrote:
gavin wrote:
just run "ant jar" in your hibernate 3.0beta4 install dir.


All up and working now thanks. I've noticed some System.out.println's in teh code, will this go in the RC ?


Oh serious??

let me check...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 04, 2005 8:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Uuummm ... I didn't find anything Bad....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 12:17 am 
Newbie

Joined: Fri Oct 17, 2003 10:56 pm
Posts: 11
gavin wrote:
If you are in a CMT environment, you should no longer need Spring. AFAICT, people use spring here for four things:

(1) session handling/flushing
(2) transaction management
(3) SQLException mapping
(4) Runtime exceptions model

Well, with hibernate.transaction.flush_before_completion and hibernate.transaction.auto_close_session, (1) is now much, much easier. (2) is handled by CMT. (3) is implemented in the Hibernate Dialect. And Hibernate3 has an unchecked exception model, so (4) is no longer relevant.


for example :
spring can manage transaction with method ,
and have transaction definitions like PROPAGATION_REQUIRED,
like:PROPAGATION_MANDATORY...
Code:
<bean id="myProductService"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="transactionManager">
<ref bean="myTransactionManager"/>
</property>
<property name="target">
<ref bean="myProductServiceTarget"/>
</property>
<property name="transactionAttributes">
<props>
<prop key="increasePrice*">PROPAGATION_REQUIRED</prop>
<prop key="someOtherBusinessMethod">PROPAGATION_MANDATORY</prop>
</props>
</property>
</bean>

how do it in hibernate3?
thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:46 am 
Senior
Senior

Joined: Tue Aug 03, 2004 2:11 pm
Posts: 142
Location: Somerset
gavin wrote:
Quote:
I am not used to doing anything with sessions or transactions as a result of the reliance on Spring.


If you are in a CMT session bean, if you enable hibernate.transaction.flush_before_completion, hibernate.transaction.auto_close_session and provide hibernate.transaction.flush_before_completion and hibernate.transaction.manager_lookup_class, then there should be not much difference. You don't need to manually handle transactions or do exception handling.


Can you point me towards the documentation on these new properties ? Do I have to manually open and close sessions, which is something I never did in the Spring version of code I was using.

I've tried going down the hibernate 3 route, and have got into loads of problems with sessions not being closed when they should be, with the result that updates don't get committed etc. I'm quite ahppy to open and close sessions manually as described in the Hibernate 2 documentation, I'm just wondering how exactly hibernate 3 makes our life easier in this respect.

I noticed you mentioned hibernate.transaction.flush_before_completion twice, was this just a typo, or is there another property missing ?

_________________
On the information super B road


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
That was a typo.

You have to manually open sessions. You do not have to close them.

Enable logging and check that org.hibernate.engine.CacheSynchronization.beforeCompletion() is getting called.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page 1, 2  Next

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.