-->
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: Criteria API design problems
PostPosted: Wed Mar 03, 2004 7:27 am 
Newbie

Joined: Wed Mar 03, 2004 7:11 am
Posts: 6
Hello,

I a fan of programatic query as most of the time
I have to generate a query from data given by the user
in a form. But I see some problems in the current Criteria API:

* It does not implement all the functionallity of hql.

* A criteria is associated with a session, so it is not possible
to store it for later retrieval (you could disconnect the session,
but ..).

Both of these problems are related to the fact that the criteria
api generates sql and executes this sql. Jus the same thing that
the session does. My concern is, would not be more logical that
the Criteria API would generate hql directly?

I mean something like:

Criteria criteria = new Criteria(Cat.class).add() ...
String hqlQuery = criteria.toHql();
session.find(hqlQuery);

This approach would have the following advantages:
* The Criteria API would generate hql instead of SQL. I understand
this is very desirable as avoid code duplication (currently
you have to generate sql from the hql code and from Criteria).

* The Criteria object is not related to any session, so you can
store, modify, reuse it ...

* You can modify the generated hql if needed to implement
things that the Criteria API does not provide.

What do you think about this? I am missiing something?

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 7:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It is not possible to recreate the same functionality the Criteria API currently has by using HQL. None of these two is a subset of the other.

There is a JIRA entry for detatched Criterias, you can vote for it here if it is important for you. But currently it does not look like it will get in in close future.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 7:48 am 
Newbie

Joined: Wed Mar 03, 2004 7:11 am
Posts: 6
And don't you think it would be more sensible to extends hql
in order to support all the functionallity of the Criteria API and
unify all the code? In the best case, it can be confusing to have to
use one method or the other in order to access to some functionallity. In the worst, you have to maintain two separate
pieces; that leads to more work and more bugs.

To be able to detach the Criteria is one of the advantages
of the "unification", but is not one of my top needs by now :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 7:49 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
The HQL parser is being rewritten for the next major Hibernate release (no schedule yet), so we might see some unification of the two APIs.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.