I am trying to fetch data from many-to-many bi direction mapping. I have three tables: eventdescription, eventtype, and eventtypedescription. eventtype is the joint table of eventdescription and eventtypedescription tables, whose primary key is the foreign key of other two tables.
public class EventDescription implements Serializable {
private Integer eventDescriptionId; private Set eventType = new HashSet(); . . public EventDescription() {}
} my EventDescription.hbn file is <class name="EventDescription" table="eventdescription"> <id name="eventDescriptionId" column="eventdescriptionid"> <generator class="native" /> </id> . <set name="eventType" table="eventtype" lazy="false"> <key column="eventdescriptionid" /> <many-to-many column="eventtypeid" class="EventTypeDescription" /> </set>
Pojo file public class EventTypeDescription implements Serializable {
private Integer eventTypeId; private Set<EventTypeDescription> events; public EventTypeDescription() {} }
EventTypeDescription.hbn file is :
<class name="EventTypeDescription" table="eventtypedescription"> <id name="eventTypeId" column="eventtypeid"> <generator class="native" /> </id>
<set name="events" table="eventtype" inverse="true"> <key column="eventtypeid" /> <many-to-many column="eventdescriptionid" class="EventDescription"/> </set>
I am not able to fetch data from eventdescription and eventtypedescription tables. If anyone knows please let me know how to write the HQL query to fetch data. I think I have to do join but my join query is not working for the two tables. It is working for one eventdescription table.
Below is the working query: List<?> result = session.createQuery("FROM EventDescription "").list();
Thanks!!!!
|