-->
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.  [ 3 posts ] 
Author Message
 Post subject: use HQL in Criteria
PostPosted: Tue Apr 03, 2007 8:38 pm 
Newbie

Joined: Tue Apr 03, 2007 5:42 am
Posts: 13
How can you do use hql by criteria?

for example,
DB schema is
+--------------------------+
| Glossary |
+--------------------------+
| gls_no int primary key |
| gls_name varchar(16) |
+--------------------------+

session.createCritera(Glossa.class)
.add(Restricionts.sqlRestrictions("name like 'H%'"))
.list();

this example occured error!

because sqlRestrictions use native sql, so then name is unkown field.

========
I must do criteria method.
How can you solve this problem?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 11:31 pm 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi slothink,

try

session.createCritera(Glossa.class)
.add(Restricionts.like("name", "H%"))
.list();


Note . Name should be property of Glossa

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 2:26 am 
Newbie

Joined: Tue Apr 03, 2007 5:42 am
Posts: 13
sorry, dharmendra.pandey.

your answer is great!

but, my fault that just easy question.
sorry about that.

because, i want to use the 'instr' function.

for example. 1. correct code.
Code:
List list = session.createQuery("from Category c where path like :searchPath and instr(c.path, '/', 1, :searchCount) = 0")
            .setParameter("searchPath", topEntry.getPath()+"%")
            .setParameter("searchCount", new Integer(searchCount))
            .list();


2. my purpose code
Code:
List list = session.createCriteria(Category.class)
where path like :searchPath and instr(c.path, '/', 1, :searchCount) = 0")
            .add(Restirctions.eq(path, topEntry.getPath(), MatchMode.END))
            .add(Restrictions.sqlRestriction("instr(path, '/', 1, "+searchCount+")) = 0")
            .list();



HQL can parse 'instr' function.
but, 'Restrictions' is not support 'instr' function. so that, i use sqlRestrictions.
but sqlRestrcitons use nativieSql, so hibernate recognized 'path' is not unknow field.

please, give me the answer, repeat.

Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.