Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DOT node with no left-hand-side using HQL with join

I am trying to find the maximum value of a Date column in mySQL DB using hibernate query language with join

@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();

Model class =

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

    @Id
    private long orderNumber;
private Date last_modified;

I am getting this error :-

Caused by: java.lang.IllegalStateException: DOT node with no left-hand-side!

Can anyone please help me out by telling me how to write this in Hibernate?

like image 889
Er KK Chopra Avatar asked Dec 18 '22 21:12

Er KK Chopra


1 Answers

Remove your package names. An entity is defined by its name only. Dots are used for properties and links between tables (when defined as a @ManyToOne* property).

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

Think Classes and Properties, not columns, when you write HQL.

like image 93
Guillaume F. Avatar answered Jan 08 '23 13:01

Guillaume F.