-->
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.  [ 3 posts ] 
Author Message
 Post subject: Save doesn't insert values in link table for a (Hash)Map
PostPosted: Thu Feb 15, 2007 6:06 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
Hello,
I'm a hibernate n00b, but an experienced Java developer. My problem occurs when saving an object with a HashMap into the database.
When I initially save the transient object, it inserts the object's data and cascades to the maps and other objects, but for some reason it never inserts any values in the link table (tk_sheet_to_row). It does save the map values to the proper tables, but the link tables remain empty.

What this means is that the object loses the references to the values. The values are there, but there's no link from the object to those values. If I do a save(), evict the object from the cache and reload the object, it has empty maps.

For some reason when later on I'm updating the object, the links are saved, but the initial save does not seem to cascade properly.

Any thoughts on this, or need for further information?


Hibernate version: 3.1

Mapping documents:
<hibernate-mapping default-lazy="false">
<class name="com.digitalchocolate.ddb.domain.toolkit.SheetImpl" table="tk_sheet">
<id name="id" column="id" type="long">
<generator class="native"/>
</id>
<discriminator/>
<timestamp name="version" column="hibernate_version" source="db"/>
<!--<version name="version" column="hibernate_version" type="timestamp"/> -->

<property name="parentId" column="parent_id" type="long"/>

<property name="name" type="string" not-null="true"/>
<property name="locked" type="boolean"/>
<property name="createStatics" type="boolean"/>
<property name="toolkitSheet" type="boolean"/>

<many-to-one name="comment" not-null="false" class="com.digitalchocolate.ddb.domain.common.CommentImpl" lazy="false" column="comment_id" cascade="persist,save-update,evict"/>

<map name="rowMap" table="tk_sheet_to_row" lazy="false" cascade="persist,save-update,evict">
<key column="rows_id"/>
<index column="row_name" type="string"/>
<many-to-many column="row_id" class="com.digitalchocolate.ddb.domain.toolkit.RowImpl"/>
</map>
<map name="columnMap" table="tk_sheet_to_column" lazy="false" cascade="persist,save-update,evict">
<key column="columns_id"/>
<index column="column_name" type="string"/>
<many-to-many column="column_id" class="com.digitalchocolate.ddb.domain.toolkit.ColumnImpl"/>
</map>

</class>
</hibernate-mapping>

Name and version of the database you are using:
MySQL 5.0.22

The generated SQL (show_sql=true):
Everything except inserts to link table.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 10:28 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
I've done further debugging and it does seem that at the initial save (where the map is still a HashMap) only the map values are saved, but the keys are not.

Since the link table has 3 columns, the parent object id, the value id and the key, and for some reason the link table doesn't get any values, it loses both the keys for the map and the link to the parent object.

Still, it saves the keys when doing an update.

Could this be due to PersistentMap? This would of course mean that there is something lacking in Hibernate's handling of HashMaps.

-Jussi


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 16, 2007 4:57 am 
Newbie

Joined: Thu Feb 15, 2007 5:46 am
Posts: 12
Location: Helsinki
Well, I have to say, I'm baffled. It seems that there's no way I can twiddle with the mapping to make it save the things needed in the link table.

Then when I try to update the object later on, it complains that there are transient instances that need to be persisted before it can be updated.

Does this mean that cascading has a bug? Or can someone show me a mapping that saves a Map of any kind (I've tried many, so don't think I'm not doing any research).

Regards,
Jussi


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