I have defined a class: Hibernatebooleandemo
There are only two attributes: ID and enabled, string and Boolean, respectively, corresponding to the IDs and IsEnabled columns in the table. The corresponding get and set methods and DAO classes are written. But the following code is strange:
String hql = "from HibernateBooleanDemo where isEnabled=false";
Session s = HibernateSessionFactory.getSession();
Transaction t = s.beginTransaction();
Query q = s.createQuery(hql);
List list = q.list();
System.out.println(list.size());
System.out.println(((HibernateBooleanDemo)list.get(0)).isEnabled());
t.commit();
HibernateSessionFactory.closeSession();
It works correctly when you write the column name, IsEnabled, in the query statement above. But when the Write attribute is enabled, it throws an exception, presumably meaning that the attribute cannot be resolved.
Have never understood what the reason. Please enlighten us.
"Amethystwish":
If "from Hibernatebooleandemo where Isenabled=false" is written as "from Hibernatebooleandemo where Enabled=false", the following error:
aused by:com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:Unknown column ' enabled ' in ' WHERE clause '
At Com.mysql.jdbc.SQLError.createSQLException (sqlerror.java:936)
at Com.mysql.jdbc.MysqlIO.checkErrorPacket ( mysqlio.java:2870)
at Com.mysql.jdbc.MysqlIO.sendCommand (mysqlio.java:1573)
at Com.mysql.jdbc.MysqlIO.sqlQueryDirect (mysqlio.java:1665)
at Com.mysql.jdbc.Connection.execSQL ( connection.java:3124)
at Com.mysql.jdbc.PreparedStatement.executeInternal (preparedstatement.java:1149)
at Com.mysql.jdbc.PreparedStatement.executeQuery (preparedstatement.java:1262)
at Org.hibernate.jdbc.AbstractBatcher.getResultSet (abstractbatcher.java:139)
at Org.hibernate.loader.Loader.getResultSet (loader.java:1669)
at Org.hibernate.loader.Loader.doQuery ( loader.java:662)
at Org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections (loader.java:224)
At Org.hibernate.loader.Loader.doList (loader.java:2145)
... 8 more