-1

I am new to hibernate and will require your assistance.

My goal is to define hibernate classes and eventually run the following SQL query

SELECT *
FROM ( SELECT *  FROM {quiz_question_instances} WHERE quiz =5 ) AS mqqi
LEFT JOIN {question_usages} mqu ON mqu.id =139
LEFT JOIN {question_attempts} mqea ON mqea.questionusageid = mqu.id
AND mqea.questionid = mqqi.question

I do not know how to do Joins in hibernate. Should I create entity classes for all the tables mentioned in this query?

Also, I am using spring to display this data to a webpage. I have a dao layer defined too. How do i write this query in my dao layer?

Thanks for all the help!

EDIT:-

Attached the columns of the database tables.

Question Attempts

enter image description here

Question Usages

enter image description here

Quiz Question Instances

enter image description here

Kaushik Balasubramanain
  • 1,248
  • 6
  • 28
  • 42
  • In hibernate you dont work with tables but you work with objects..It would be of use to us if you give your object structure and how you mapped it – steelshark Apr 01 '14 at 13:59
  • I create a class for each table. I map every column to a variable and use the @Column annotation. I do not know how to declare the columns which come from the join as a variable. That is where I am seeking help :) – Kaushik Balasubramanain Apr 01 '14 at 17:40
  • Hibernet handles joins itself, u have to only create its **hbm** or declared **annotation** – Ashish Ratan Apr 01 '14 at 18:32
  • Hi Ashish, can you let me know any tutorial that i can follow for this? – Kaushik Balasubramanain Apr 01 '14 at 19:01
  • As said above here, hibernate automaticly maps joincolumns..You have to use the ManyToOne / ManyToMany (jointable) annotations for this..In combination with JoinColumn – steelshark Apr 02 '14 at 06:48

1 Answers1

0

You can help in the interfaz Criteria (org.hibernate.Criteria), HQL,...

Here there is a solution for joins:

Hibernate Criteria Join with 3 Tables

You also have an explication:

http://kruders.com/hibernate/hibernate-criteria-on-multiple-tables/

I hope help you.

Community
  • 1
  • 1
Ltcs
  • 263
  • 1
  • 3
  • 15