PDA

View Full Version : Preliminary Hibernate3 and spring integration



karaznie
Aug 30th, 2004, 02:14 AM
Hi,

During the weekend I implemented basic support for Hibernate3 in spring. This task was very simple, as HB3 is highly compatible with 2.0 (with some exceptions). Doing this i've found few interesting things:

* Hibernate Exceptions are unchecked now,
* Hibernate team changed signature of few exceptions methods from Class getPersistentClass() to String getPersistentClass. Unfortunatelly it affects exceptions in org.spring.framework.orm package (Currently i decided pass nulls instead of Classes - I must investigate why they changed this and what exactly they pass in returned value - I wonder if it has something in common with named-entities),
* There are deprecated methods in Session (moved to org.hibernate.classic.Session) like int delete(...), seveOrUpdateCopy(...) - so I removed them from HibernateTemplate,
* UserType was moved to org.hibernate.usertype.UserType,
* UserType got two new methods: assemble and disassemble (like CompositeUserType) for better control over caching (affects spring Clob/Blob user types),

Refectoring current spring code was quite simple tasks, but there are few
minor problems. I just copied all orm.hibernate.* classes into new package orm.hibernate3. I didn't decide to add "3" suffix to hibernate classes, because I didn't find elegant way to add this suffix to classes like ClobStringType etc. Currently I didn't implement all new Session's methods (I will do this today). I didn't refactored test suite yet, but I unit test the code with all my applications and all tests passed.

I don't know how to attach files in the forum, so if somebody is interested in - please contact me at karaznie@cetelem.pl

ps. I wonder why there is no support for Critera, Query and SQLQuery in original HibernateTemplate. Ofcourse You can always get original Hibernate session and create Queries, but You have to get (proper) current session etc. It would be nice to have convinient methods for this in HibernateTemplate, wouldn't be?

Artur

Colin Sampaleanu
Aug 30th, 2004, 08:21 AM
Artur,

All the method calls on HibernateTemplate are self contained, since the Session has to be managed, and exceptions have to be mapped. So it is expected that if you need to use Criteria, Query, adn SQLQuery, you do it inside a callback block (i.e. HibernateCallback).

The place for putting code so it doesn't get lost is in JIRA actually, as an enhancement request (alternate place is the Confluence wiki, for code that will probably not ever make it into Spring but is useful beside it).

Juergen Hoeller
Aug 30th, 2004, 03:32 PM
FYI, I've just added overloaded constructors that take a persistentClassName String to ObjectOptimisticLockingFailureException and ObjectRetrievalFailureException. You should be able to pass the Hibernate3 persistentClass Strings in there now, as alternative to Class objects.

Juergen

karaznie
Aug 31st, 2004, 07:39 AM
FYI, I've just added overloaded constructors that take a persistentClassName String to ObjectOptimisticLockingFailureException and ObjectRetrievalFailureException. You should be able to pass the Hibernate3 persistentClass Strings in there now, as alternative to Class objects.
Juergen

Thanks - this is great!

I just added JIRA and attached with basic hibernate3 source code support for spring sandbox. For people who are interested in http://opensource.atlassian.com/projects/spring/browse/SPR-300

Artur

karaznie
Sep 2nd, 2004, 05:04 AM
I just uploaded complete (say - more complete:) support for Hibrnate3-alpha into JIRA. I added new "entity-name" related methods, added test suite for new methods and all test passed.

If You are interested in - just download, unpack into Your springframework directory and compile (don't forget about hibernate3 and antlr jars).

Artur

Rod Johnson
Sep 2nd, 2004, 12:03 PM
Artur

Cool stuff! Thanks.