-->
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: Create Expression for associations without createCriteria.
PostPosted: Tue Dec 30, 2003 3:04 am 
Newbie

Joined: Tue Dec 30, 2003 2:49 am
Posts: 2
Location: Melbourne/Brisbane, Australia
Hi,

Is it possible to create an expression on attributes of an associated object by using just Expression and not createCriteria() for the association ?

I'd like to keep the layer in my application that constructs the expressions free from the Criteria stuffm and just pass in a collection of Expressions for the query. If I use createCriteria, I have to handle Hibernate exceptions, and have access to the Hibernate session, which I've abstracted out at the lower layer too.

Initially I thought that dot notation would work for associations, for example I could do the following (using a User object with an associated Address):

Code:
List criteriaList = new ArrayList();
Expression("name", "smith");
Expression("address.suburb", "Richmond");

queryWithCriteria(User.class, List)


where queryWithCriteria() constructs the actual Criteria using the list, and calls .list();

It seems that the dot notation works for components, but not for associtions, so I'd have to have access to the Criteria at the higher level, which kind of breaks my nice abstraction :-(

Any ideas ?

Cheers,
Darren.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 30, 2003 11:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, you can parse your expression at a lower level and manually break it up in your code where you build your criteria query.


Top
 Profile  
 
 Post subject: Create custom Criterion for associations
PostPosted: Wed Dec 31, 2003 1:09 am 
Newbie

Joined: Tue Dec 30, 2003 2:49 am
Posts: 2
Location: Melbourne/Brisbane, Australia
Yeah, I was thinking along these lines at first myself.

If I parsed the dot notation and created my own Criteria I'd break the use of the dot notation for components. I suppose I could use another convention.

I'm now thinking along the lines of creating a custom Criterion (something like AssociationEqExpression which would have to override the getColumns() in the AbstractCriterion class and implement its own toSqlString(..) (and not extent SimpleExpression.

Does this sound a reasonable approach to anyone, or am I heading too far off track ??

Cheers,
Darren.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 31, 2003 6:31 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
How would you add in the necessary join? Well, I guess its possible....


If you manage to get something like this working, please share, it would be really great if we could get it in the HIbernate core!


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.