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.  [ 1 post ] 
Author Message
 Post subject: Associations query
PostPosted: Thu Sep 18, 2008 1:36 am 
Hello all,
I ve recently started working on Hibernate. I have queries related to persisting collections and their associations.

My application has two POJOs FacilityBean and FloorBean mapping to entities Facility and Floor. FacilityBean has a set of floors as i want the set of floors associated with the facility to be retrieved along with it. And Floor has a Facility object as every floor belongs to a facility (there are no foreign keys involved).

Mapping Xml is like this:

Facility :
<hibernate-mapping default-access="field">
<class name="com.spring.orm.FacilityBean" table="fm_facility_master">
<id name="Id" column="FM_FACILITY_ID" >
<generator class="native" />
</id>
<property name="parent" column="FM_FACILITY_PARENT_ID" />
......
<property name="default_loc" column="FM_DEFAULT_LOC" />

<set name="floors" lazy="false" table="facility_floor" cascade="none">
<key column="FM_FACILITY_ID"/>
<many-to-many column="FL_FLOOR_ID" unique="true"
class="com.spring.orm.FloorBean"/>
</set>
</class>
</hibernate-mapping>

Floor:

<hibernate-mapping default-access="field">
<class name="com.spring.orm.FloorBean" table="fl_floor">
<id name="Id" column="FL_FLOOR_ID" >
<generator class="native" />
</id>
<property name="floorName" type="java.lang.String" column="FL_FLOOR_NAME"/>
<property name="facilityId" column="FL_FACILITY_ID"/>

<join table="facility_floor" inverse="true" optional="true">
<key column="FL_FLOOR_ID"/>
<many-to-one name="facility" column="FM_FACILITY_ID" cascade="all" not-null="true"/>
</join>
</class>
</hibernate-mapping>

I can persist the collection only when i am inserting both the entities together.
I want to insert a new floor seperately and also update the association table facility_floor like insert new floor object and the FacilityId and the new FloorID gets written into to the association table.

Can anyone please help me to know how can i do this.
I believe that hibernate will insert data into the association join table only when new entries of the entities like facility and floor are inserted together.
Please help.


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

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.