-->
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: QBE concat
PostPosted: Wed Feb 09, 2005 7:19 am 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
Hibernate version:2.1.7

Hi I am trying to convert a JDBC query:

"and lower(concatenate(e.first_name,' ',e.last_name'))
like lower('%"+off.getDriverName()+"%')");

Into a QBE query..

criteria.add(Expression.ilike("firstName surName", offence.getDriverName(), MatchMode.ANYWHERE));

Is there any elegant way of doing this?

I could split the getDriverName() based on spaces and break the query into a like (first_name) OR like (surname) or something...

but a cleaner solution would be nicer :)

Any ideas?



Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: I guess Hibernate does not support this then?
PostPosted: Wed Feb 09, 2005 12:04 pm 
Beginner
Beginner

Joined: Thu Oct 14, 2004 5:07 am
Posts: 37
Location: Cambridge, UK
I am trying to replace:

and concatenate(e.first_name,' ',e.last_name')) like '%aperson%')

in QBE?

Is there anyway of setting up some sort of Hibernate field fullName view? that consists of the firstName and lastName fields? and then reference that field in the QBE query?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 7:31 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
Did you resolve this? I'm having the same problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 8:27 am 
Newbie

Joined: Mon Feb 19, 2007 5:10 am
Posts: 15
I have found a workaround. I define a property formula in the mapping file which does the concatenation:

Code:
    <property name="ForenameSurname" formula="forename + ' ' + surname" type="String"/>
    <property name="PreferredNameSurname" formula="forename + ' ' + surname" type="String"/>


I can then refer to these properties in my search code:

Code:
ICriterion matchName =
  Expression.Or(
    Expression.InsensitiveLike("contact.ForenameSurname", filter.Member, MatchMode.Anywhere),
    Expression.InsensitiveLike("contact.PreferredNameSurname", filter.Member, MatchMode.Anywhere)
  );


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.