Hibernate version: 3.2.2
Mapping documents:
Associate.hbm.xml
Code:
<hibernate-mapping>
<class name="ad.VO.Associate" table="t1">
<id name="id" column="ID" type="string"/>
<property name="name" type="string" column="NAME"/>
<many-to-one name="dept" column="DID" class="ad.VO.Department" not-null="true"/>
</class>
</hibernate-mapping>
Department.hbm.xml
Code:
<hibernate-mapping>
<class name="ad.VO.Department" table="t2">
<id name="did" column="DID" type="string"/>
<property name="dname" type="string" column="DNAME"/>
<set name="associates" inverse="true" fetch="join">
<key column="DID"/>
<one-to-many class="ad.VO.Associate"/>
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session newSession = HibernateUtil.getSessionFactory().getCurrentSession();
newSession.beginTransaction();
Criteria criteria = newSession.createCriteria(Associate.class);
results = new ArrayList();
results = (ArrayList) criteria.list();
newSession.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
Full stack trace of any exception that occurs:No exceptions
Name and version of the database you are using: DB2 v8.1
The generated SQL (show_sql=true):Code:
select this_.ID as ID0_0_, this_.NAME as NAME0_0_, this_.DID as DID0_0_ from t1 this_
The problem
I'm just trying to create a simple association between two tables. The associate table contains the id, name and department id. The department table contains department id and department name. I'm just trying to get complete list of associates with the corresponding department names.
But as you see in the generated SQL, it is not creating any join with the department table.
Please advise. Thank you.