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: Expression.like doesn't work with MSSQL
PostPosted: Mon Jul 11, 2005 7:11 pm 
Newbie

Joined: Mon Jul 11, 2005 7:04 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="pts.data">

<class name="TesterV" table="tester_v2" mutable="false" schema="ngptd.ptd_admin">
<composite-id>
<key-property name="testerName" column="tester_name" type="java.lang.String" />
<key-property name="testerType" column="tester_type" type="java.lang.String" />
</composite-id>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Criteria crit = session.createCriteria(TesterV.class);

/* Do SELECT */
Projection proj = Projections.property("testerName");
crit.setProjection(proj);

/* Do WHERE */
Disjunction disj = Restrictions.disjunction();
disj.add(Restrictions.eq("testerType", "TUBES"));
disj.add(Restrictions.eq("testerType", "GENERATOR"));
crit.add(disj);

crit.add(Expression.like("testerName","?"));

/* Do ORDER BY*/
crit.addOrder(Order.desc("testerName"));

/* Get Results */
List testers = crit.list();
System.out.println(testers);


Full stack trace of any exception that occurs:

Name and version of the database you are using:MSSQL 2000

The generated SQL (show_sql=true):
Hibernate: select this_.tester_name as y0_ from ngptd.ptd_admin.tester_v2 this_ where (this_.tester_type=? or this_.tester_type=?) and this_.tester_name like ? order by this_.tester_name desc


Debug level Hibernate log excerpt:

When I add the above like expression, or any variation of that expression that I can possibly think of, Hibernate brings back 0 results. I've tried different tables, different strings, different columns. Has this happened to anyone else before?


Top
 Profile  
 
 Post subject: Re: Expression.like doesn't work with MSSQL
PostPosted: Mon Jul 11, 2005 7:37 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
craig_hanna wrote:
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="pts.data">

<class name="TesterV" table="tester_v2" mutable="false" schema="ngptd.ptd_admin">
<composite-id>
<key-property name="testerName" column="tester_name" type="java.lang.String" />
<key-property name="testerType" column="tester_type" type="java.lang.String" />
</composite-id>
</class>

</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Criteria crit = session.createCriteria(TesterV.class);

/* Do SELECT */
Projection proj = Projections.property("testerName");
crit.setProjection(proj);

/* Do WHERE */
Disjunction disj = Restrictions.disjunction();
disj.add(Restrictions.eq("testerType", "TUBES"));
disj.add(Restrictions.eq("testerType", "GENERATOR"));
crit.add(disj);

crit.add(Expression.like("testerName","?"));

/* Do ORDER BY*/
crit.addOrder(Order.desc("testerName"));

/* Get Results */
List testers = crit.list();
System.out.println(testers);


Full stack trace of any exception that occurs:

Name and version of the database you are using:MSSQL 2000

The generated SQL (show_sql=true):
Hibernate: select this_.tester_name as y0_ from ngptd.ptd_admin.tester_v2 this_ where (this_.tester_type=? or this_.tester_type=?) and this_.tester_name like ? order by this_.tester_name desc


Debug level Hibernate log excerpt:

When I add the above like expression, or any variation of that expression that I can possibly think of, Hibernate brings back 0 results. I've tried different tables, different strings, different columns. Has this happened to anyone else before?


Why are you specifying "?" as the like value ? Do you mean to add 'where testerName = '?*'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 12, 2005 11:12 am 
Newbie

Joined: Mon Jul 11, 2005 7:04 pm
Posts: 2
I used just "?" because I was hoping to get back the same result as if I hadn't included the LIKE constraint at all, to rule out capitalization or spaces, etc. I figure if the criteria w/o LIKE '?' returned 6 instances, the same should be true with LIKE '?'.


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.