20030309 Sunday March 09, 2003

Hibernate Enhancements For you Hibernate users/lovers, here's some good news for you (THANKS GAVIN!):

1. [Hibernate Forum] For XDoclet users its well-worth grabbing a CVS update now, I have fixed a bunch of issues and made improvements including Hibernate2 support (thanks to Matt Raible) and joined-subclass support.

2. [Hibernate Dev List]

 After a bit of research and thinking, I have settled on an approach to
 query by Criteria that hopefully is flexible enough for 80-90% of use
 cases, but still simple enough to fit in sufficiently few lines of code.
 
 The proposed new API is based loosely upon the Cayenne API. Queries may be
 expressed as follows:
 
 
 List cats = session.createCriteria(Cat.class)
     .add( Expression.like("name", "Izi%" ) )
     .add( Expression.between("weight", minWeight, maxWeight) )
     .add( Expression.eq( "mate", mate ) )
     .addOrder( Order.asc("age") )
     .setMaxResults(20)
     .list();
 
 
 Which is approximately equivalent to:
 
 from Cat cat
 where cat.name like 'Izi%'
 and cat.weight between :minWeight and :maxWeight
 and cat.mate = :mate
 order by cat.age
 
 
 This API is marked "experimental", but I would like to stabilize it fairly
 soon, so early feedback is very welcome. This is all in CVS.

Posted in Java at Mar 09 2003, 09:56:16 AM MST 3 Comments

Comments:

This is very very cool. I am still reading Hibernate docs trying to learn all that I can. One source that I am using is struts-resume. I have a question, why pass around session? What is the reason for not putting currentSession() in BaseDAOHibernate? The session is a Hibernate session, hence Hibernate specific. So all of the work that you put in to have an abstract implementation is for naught because I doubt other persistance layers are going to use a Hibernate Session. You are also tying your View to your Model. Or have I totally nuked this and am missing something?

Posted by Carl on March 09, 2003 at 03:01 PM MST #

It's a good point, but I only want to create/obtain one session per web request. If I do it on the service or DAO level, then I'd have to do it on a method level, rather than passing it around. What would be better is to pass around some generic connection object that could be a database connection, a hibernate session or something like that. That's probably the route I should go. Thanks for the feedback - keep it coming!

Posted by Matt Raible on March 09, 2003 at 04:46 PM MST #

Why not save it in a ThreadLocal? That's what I'm doing at work and in the beginnings of XRoller (our XWork / WW2 version of Roller)

Posted by Anonymous on March 11, 2003 at 01:45 PM MST #

Post a Comment:
  • HTML Syntax: Allowed
Click me to subscribe
Matt Raible is a Web Architecture Consultant specializing in open source frameworks.
« May 2012
SunMonTueWedThuFriSat
  
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
  
       
Today

Recent Entries

Tag Cloud