0

I searched a lot around but cannot find the answer:

I have the following SQL query:

select distinct l.id_book from wa2011.tb_lending as l where l.id_user = 1

It's a very simple query but I cannot manage to write it. How can I write this in HQL?

Thanks a lot! Cheers.

LucasM
  • 391
  • 2
  • 7
  • 21

1 Answers1

1

I tested the code with Hibernate 3.3.2 and MS SQL Server and it works fine:

select distinct u.id from User u where u.login='admin'

So I think your HQL code should looks almost the same (just rewrite it from SQL to object model mapped to Hibernate).

FoxyBOA
  • 5,688
  • 6
  • 43
  • 72
  • Thanks for your answer. The problem is that the field I want to be unique is actually another object. If I put the clause "distinct x.bookBean bla bla bla" the result will be a list of BookBean object and not of the object on the "from" clause. – LucasM May 08 '11 at 14:20
  • Tested with many-to-one mapping and also everything works fine. Which exception did you get? – FoxyBOA May 09 '11 at 06:41