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.
|