-->
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.  [ 4 posts ] 
Author Message
 Post subject: cascade and mapping a map of references
PostPosted: Mon Jun 20, 2005 4:56 pm 
Beginner
Beginner

Joined: Mon May 09, 2005 5:26 pm
Posts: 21
Hello,

I'm trying to map the following Object relations:
AssemblyType - contains a Collection of Assemblies
Assembly - contains a map with the key bieng of type PiecePart and the value being an Integer representing the quantity of said part.

I wish to perform a "save" on the AssemblyType and have it cascade through to the PiecePart level. Relavent bits of my mapping files:

AssemblyType.hbm.xml:
-----------------------------
<set name="assemblyList" inverse="true" lazy="false"
cascade="persist,merge,save-update,delete-orphan">
<key column="assemblyTypeID"/>
<one-to-many class="Assembly"/>
</set>


Assembly.hbm.xml:
-----------------------
<many-to-one name="AssemblyType" column="assemblyTypeID" class="AssemblyType"/>

<map name="piecePartMap" table="AssemblyPieceParts" lazy="false"
cascade="persist,merge,save-update">
<key column="assemblyID"/>
<map-key-many-to-many class="PiecePart" column="partID"/>
<element type="int" column="quantity"/>
</map>


PiecePart.hbm.xml: (nothing special here)
----------------------
<property name="partNumber" type="string" unique="true" not-null="true"/>
<property name="description" type="string" not-null="true"/>


These mapping files build the tables I wish and work *if* the PieceParts are already defined, but generate a TransientObjectException if a PiecePart is not yet defined. I was able to hack a "solution" to force a save of the PiecePart by modifying Assembly.hbm.xml to include:

<set name="pieceParts" table="PiecePartHack" lazy="false"
cascade="persist,merge,save-update">
<meta attribute="description">
A (hopefully-temporary) hack to force hibernate to persist parts
before creating the map table "piecePartMap"
</meta>
<key column="piecePartID"/>
<many-to-many class="PiecePart"/>
</set>

This cobbled hack forces me to keep an extra Collection on the Java side and create an extra table on the db side -- not ideal.

I'm far from an expert (which is perhaps obvious), but have read the forum, The Book, and anything else I can get my hands on -- so if the solution should be obvious, please blame ignorance rather than laziness.

thanx,

-don.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 20, 2005 10:05 pm 
Beginner
Beginner

Joined: Mon May 09, 2005 5:26 pm
Posts: 21
I should have noted that I'm using Hibernate3.

thanx,

-don.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 8:36 am 
Beginner
Beginner

Joined: Mon May 09, 2005 5:26 pm
Posts: 21
i know this is a cheap trick to get the post back to the front, but really -- does *anyone* have *any* suggestions?

thanx,

-don.


Top
 Profile  
 
 Post subject: I am having the same issue
PostPosted: Thu Sep 15, 2005 11:25 pm 
Newbie

Joined: Thu Sep 15, 2005 11:10 pm
Posts: 2
Yes I noticed the "cascade save" wouldn't save map key objects before main object so you get a transient object error. I had to call .save() on map key object first. This can be inconvenient.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.