每日一得-org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!错误解决办法

org.hibernate.hql.ast.QuerySyntaxException: Path expected for join!

HQL进行JOIN连接查询时需要注意几点:

1.HQL不支持ON,需要将ON换成WHERE

2.需要注明对象之间的映射关系


Product.hbm.xml映射文件如下:


Product类中需要有

private Book book;

HQL语句:

String hql = "select new com.entity.BookInfo(p.id,p.productName,p.fixedPrice,p.dangPrice,p.addTime," +
     "b.author,b.publishing,b.publishTime,b.catalogue,p.productPic)"+
         "from Product p, Book b where p.id=b.id and b.publishTime=(" +
         "select max(b.publishTime) from Product p join p.book b where p.id=b.id)";

你可能感兴趣的:(hibernate学习)