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

  • Post author:
  • Post category:其他


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

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

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

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

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

<one-to-one name=”book” class=”com.entity.Book” fetch=”join”/>

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)”;



版权声明:本文为hk540610原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。