hibernate 中使用where 报unexpected token错误。

来源:百度知道 编辑:UC知道 时间:2024/06/25 09:27:48
Configuration configuration = new Configuration().configure();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
String hqlString = "from Book where bookType:BookType";
Query query = session.createQuery(hqlString);
query.setInteger("bookType", 1);
List<BookInfo> bookTypeArrayList = query.list();
session.close();
return bookTypeArrayList;
Book是Pojo不是表名~~~~~~
运行时报unexpected token: : near line 1, column 38 [from com.po.BookType where bookTypeID:bookTypeID]
Configuration configuration = new Configuration().configure();
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
String hqlString = "from BookType where bookType:BookType";
Query query = session.createQuery(hqlString);
query.setInteger("bookType", 1);
List<BookInfo> book

String hqlString = "from Book where bookType:BookType";
改成
String hqlString = "from Book where bookType = :BookType";

from com.po.BookType where bookTypeID:bookTypeID
不确定有这种用法。。。。
最好把错误日志都贴出来给看看

BookType如果不是表名,那“hqlString = "from BookType where bookType:BookType";”怎么行的通?"from"语句查的就是数据库表。