没有左侧的DOT节点使用带有连接的HQL

时间:2015-11-27 18:24:23

标签: java mysql sql hibernate

我试图使用带有连接的hibernate查询语言在mySQL DB中找到Date列的最大值

@Query("select o.techid, CAST(MAX(o.last_modified) AS DATE) 
   from com.dw.model.user.User as u 
   left join com.dw.model.order.Order as o 
     on u.username=o.techid group by o.techid")
List<User> findUsers();

模型类=

@Entity(name = "orders")
@Scope("prototype")
@Component
@JsonIdentityInfo(generator = ObjectIdGenerators.IntSequenceGenerator.class)
public class Order {

    @Id
    private long orderNumber;
private Date last_modified;

我收到此错误: -

引起:java.lang.IllegalStateException:没有左侧的DOT节点!

有人可以通过告诉我如何在Hibernate中写这个来帮助我吗?

2 个答案:

答案 0 :(得分:7)

删除您的包名称。实体仅由其名称定义。点用于表之间的属性和链接(当定义为@ ManyToOne *属性时)。

select o.techid, CAST(MAX(o.last_modified) AS DATE) 
   from User as u 
   left join Order as o 
     on u.username=o.techid group by o.techid

在编写HQL时,请考虑类和属性,而不是列。

答案 1 :(得分:0)

尝试以下解决方案,这应该可行

SELECT o.techid, CAST(MAX(o.last_modified) AS DATE) 
FROM User u LEFT JOIN u.order o GROUP BY o.techid