-->
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: Problems saving map
PostPosted: Mon Feb 12, 2007 4:14 am 
Newbie

Joined: Sun Sep 03, 2006 9:39 am
Posts: 5
Hello!

I have a class with following properties:

Code:
public class Action {   
   private int actionId;   
   private String className;
   private final Map<String, String> labels = new HashMap<String, String>();
[... Getters and Setters ...]
}


The mapping file is following

Code:
<hibernate-mapping>
    <class name="ch.arpage.collaboweb.model.Action" table="actions" catalog="collaboweb" lazy="false">
        <comment></comment>
        <id name="actionId" type="int">
            <column name="ACTION_ID" />
            <generator class="assigned" />
        </id>
        <property name="className" type="string">
            <column name="CLASS" length="100">
                <comment></comment>
            </column>
        </property>
        <map name="labels" table="action_labels" cascade="all">
           <key column="ACTION_ID"/>
           <map-key type="string" column="LANGUAGE"/>
           <element type="string" column="LABEL"/>
        </map>
    </class>
</hibernate-mapping>


When in my application I call t

Code:
Action action = new Action();
action.setClassName("actions.Test");
action.setLabel("de", "Test");
action.setLabel("en", "Test");
getHibernateTemplate().save(action);


then, the action object is saved in the actions table but the action_labels table (mapped on labels Map) is not saved.
Do you see what I did wrong?

Thanks a lot and regards,
Patrick
[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 8:02 am 
Newbie

Joined: Sun Sep 03, 2006 9:39 am
Posts: 5
Hello!

I found the problem: my map property was defined as

Code:
private final Map<String, String> labels = new HashMap<String, String>();


with a setter method

Code:
public void setLabels(Map<String, String> labels) {
  this.labels.clear();
  this.labels.putAll(labels);
}


I removed the final keyword, changed the setter into


Code:
public void setLabels(Map<String, String> labels) {
  this.labels = labels;
}


and now it works (but Honestly I haven't still understood why)

Regards,
Patrick


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.