-->
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: yes_no type question
PostPosted: Mon Mar 07, 2005 10:42 pm 
Newbie

Joined: Sun Mar 06, 2005 10:20 am
Posts: 7
Hi,

my spec...
mysql 4.0.18
JDK 1.4.2_06
hibernate 2.1.7

I have a question regarding yes_no type.

my xml mapping file.

<hibernate-mapping pakage="my.hibernate">
<class name="Admin" table="admin">
<id name="id" column="ad_id" type="long" >
<generator class="native" />
</id>
<property name="fullAccess" column="ad_fullaccess" type="yes_no" not-null="true"/>
.......
..
</class>
</hibernate-mapping>

// my class : my.hibernate.Admin.java
package my.hibernate;

public class Admin
{
protected long id;
protected boolean fullAccess;
.....
public Admin() {}
}

I have a record in admin table which is id=1 and fullAccess='Y'.

HQL Query 1
select admin from Admin as admin where admin.fullAccess=true


HQL Query 2
select admin from Admin as admin where admin.fullAccess='Y'


When I use HQL query 1,
Exception occur and messages are shown below:
1 errors occurred while listing (and calling getPathNames).
net.sf.hibernate.exception.SQLGrammarException: Could not execute query
java.sql.SQLException: Column not found message from server: "Unknown column 'true' in 'where clause'"

But if I use HQL query 2,
The query return result.

My Questions are:
1.Is query 1 correct? (no script error)
2.Can we use 'true' and 'false' word in HQL to represent boolean value?
3.The type for fullAccess is boolean, why I can't use 'true' or 'false' word in HQL?
4.If HQL Query 2 is only script to retrive my data, I feel HQL a bit troublesome because I need to remember/refer all the boolean properties set to yes_no type, true_false type or byte...

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 09, 2005 6:45 pm 
Beginner
Beginner

Joined: Fri May 21, 2004 12:21 pm
Posts: 22
Location: Sacramento CA, USA
When you are using HQL the query parser will ignore the mapping document(*.hbm.xml). So when you are executing a HQL you have to specify the value in the Database. That is why your query 2 works and not 1.


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.