0

I have asked a question here

The solution is :

select * from table_name t
inner join 
    (select max(seq) seq, row_name from table_name group by row_name) t1 on t1.row_name = t.row_name and t.seq = t1.seq

But I need to convert it to HQL. The solution uses a subquery in FROM which is not allowed in HQL.

How can I convert the subquery to HQL using SELECT or WHERE?

Thanks.

James
  • 1,819
  • 2
  • 8
  • 21
Shazam
  • 105
  • 1
  • 7

1 Answers1

0

You can achieve your goal through Hibernate Native Query, see this

Try this

List<Object[]> objects = session.createNativeQuery(
                "select * from table_name t"
                + "inner join"
                + "(select max(seq) seq, row_name from table_name group by row_name) t1"
                + "on t1.row_name = t.row_name and t.seq = t1.seq")
.list();

This example shows using subquery in HQL through native query

majurageerthan
  • 2,169
  • 3
  • 17
  • 30