-->
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.  [ 2 posts ] 
Author Message
 Post subject: Using Long data type in criteria query.
PostPosted: Wed Mar 19, 2008 5:26 pm 
Newbie

Joined: Mon Mar 17, 2008 2:09 pm
Posts: 8
Hi All,

I'm using below code for getting the record for matching 'TicketId'

Criteria crit = HibernateUtil.getSessionFactory()
.getCurrentSession().createCriteria(HelpManager.class);
crit.add(Restrictions.eq(mainCriteria, new Long(ticketId)));
List result = crit.list();

This is working fine(example, if I'm passing 'ticketId' 70 and it is retrieving the record for 70).

Now I'd like to get the records which are starting with 7(so I'm trying with 7% in like query but it is not working). It is throwing error. I'm trying like query in below way:

Criteria crit = HibernateUtil.getSessionFactory()
.getCurrentSession().createCriteria(HelpManager.class);
crit.add(Restrictions.like(mainCriteria, criteria1));
List result = crit.list();

The 'criteria1' is having value '7%' and 'mainCriteria' is having 'TicketId'.

Please let me know, in case the data type is 'String' then it is working fine.

Thanks in advance.

Regards,
Sharath Karnati.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 20, 2008 10:42 am 
Newbie

Joined: Fri Mar 14, 2008 3:01 pm
Posts: 8
Location: Marysville, PA
tsql, not hql, 'like' only works with strings. for this to work you'll need to convert the long to a string.
I'm brand new to nhibernate, so I'm not sure how (if possible) to generate the sql
Code:
select * from foo where convert(varchar, ticket_id) like '7%'


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