These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Generated SQL does not create join (one-to-many association)
PostPosted: Fri Dec 21, 2007 12:37 am 
Newbie

Joined: Fri Dec 21, 2007 12:19 am
Posts: 1
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 5:42 am 
Pro
Pro

Joined: Tue Jun 12, 2007 4:13 am
Posts: 209
Location: Berlin, Germany
Hi,

I think the association
Quote:
<many-to-one name="dept" >


should have the "cascade" option!

Carlo


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.