-->
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: spring and nHibernate, how does the java world use it?
PostPosted: Thu Dec 29, 2005 4:41 pm 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
I'm very interested in using the experience that was gained by the hibernate community and their best practices. One of the things that keeps popping up is their use of the spring framework together with hibernate.

I however do not fully understand what the use of it would be. I see that I can use it (right now) as a container for my session factory and gain easy singleton acces to it.
But can anyone explain how spring is used for other things within the hibernate community and does spring.net offer us the same possibilities or not yet? Templates?


Top
 Profile  
 
 Post subject: Spring makes life easier
PostPosted: Sun Jan 01, 2006 5:17 pm 
Newbie

Joined: Mon Nov 07, 2005 6:11 pm
Posts: 6
My team uses Spring with Hibernate because it keeps our code very clean. We use Service objects together with DAOs (business logic in service objects, db queries and updates in the DAOs). By wrapping our service objects with Spring's transaction manager via the Spring config file we keep our code free of any database transaction code.

In fact, there is absolutely no database related code at all in our applications. We let Spring initialize Hibernate and inject our Hibernate based DAOs into our service objects, and then simply call the save, update, delete methods on them to persist our data.

The biggest advantage to using Spring in my opinion is that it frees you from writing the tedious non application specific code most applications need - opening and closing database connections, beginning committing and rolling back transactions, satisfying dependencies between objects, etc. There is remarkably little plumbing code in Spring applications. That cuts down on your development time and keeps all your code specific to the business problems you are dealing with. I like that.


Top
 Profile  
 
 Post subject: Re: Spring makes life easier
PostPosted: Sun Jan 01, 2006 11:33 pm 
Newbie

Joined: Sat Dec 31, 2005 6:21 pm
Posts: 4
I am completely new to both spring and hibernate (a couple of weeks). I have been toying with a trivial test program using hibernate and hibernate/spring. After getting past the worst part of the green-newbie learning curve, I found myself somewhat comfortable with both. However, I noticed that plain hibernate3 is many times faster than hibernate3/spring. I eliminated some of the obvious mistakes with spring (e.g. make sure and use dbcp pooling, ...), and that made things faster, but it is still pretty bad. The worst performance hit seems to be when I insert many collection items (simple strings) into an object. If I do it with plain hibernate3, it is very fast. Spring does something that slows things down by several orders of magnitude, but I have not been able to figure out what. For instance, if I insert 50 strings into a collection, plain hibernate3 will take 0.0n seconds. With spring, it will take up to 2 seconds. I'm not sure why and it is not obvious where to look. The hit seems to be in the spring flush() operation.

I tried to read the spring code and never could figure out what it could be doing to slow things so badly. I quickly got lost in the weeds here. I noticed that the spring hibernate3 code, for example never does begin/commit transactions and relies on the session close autocommit (???). I do not know if that would make any performance difference.

I'm sure that there is some obvious configuration knob that I have not yet found that will make things behave better. However, I found it a lot less time consuming to just write the hibernate code that I need rather than try to figure out how spring was getting in the way rather than helping. This is too bad because I really wanted to use the "free" transaction management and exception handling from spring.

_________________
Julio Garcia


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 02, 2006 5:28 am 
Senior
Senior

Joined: Thu Aug 25, 2005 3:35 am
Posts: 160
okay, great information guys. Thank you very much.

We use service objects as well, and seperate DAO objects.
The obvious question is, will the spring.Net framework offer the same advantages as spring for the java platform?


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.