Method of querying Boolean value in EJB3.0

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.