-->
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: <map> question
PostPosted: Thu Oct 26, 2006 8:47 am 
Senior
Senior

Joined: Sun Jun 11, 2006 10:41 am
Posts: 164
Hi all,
I have a simple parent-child relationship: Obj-Item
Obj holds a MAP of Items, where the map key is the 'name' of the Item. However, 'name' is NOT the id of the Item.

Somewhere outside my app, an item's NAME may change. What is the best way to reflect this change in my app? calling refresh(obj) doesn't work because it refreshes the items of that object, WITHOUT refreshing the keys in the map, i.e. after refresh, I get:
old name=item with new name
instead of
new name=item with new name

Thanks.

The code (outside the app) that used to update the item name is:

Code:
obj = (Obj)session.load(Obj.class, new Long(1));
item = obj.getItems().get("old name");
item.setName("new name");
session.update(sub);


Hibernate version:
3.1

Mapping documents:
Code:
<hibernate-mapping>
    <class name="hib_refresh1.Item" table="ITEM"
    discriminator-value="hib_refresh1.Item">
   
        <id name="id" column="ITEM_ID">
            <generator class="native"/>
        </id>

        <discriminator column="CLASS" not-null="true" type="string"/>
        <property name="val" column="VAL" not-null="true"/>
        <property name="name" column="NAME" not-null="true"/>
        <map name="subs" cascade="all-delete-orphan" inverse="true" lazy="false">
            <key column="ITEM_ID" not-null="true"/>
            <map-key formula="SUB_ID" type="long"/>
            <one-to-many class="hib_refresh1.Sub"/>
        </map>
    </class>
</hibernate-mapping>

<hibernate-mapping>
    <class name="hib_refresh1.Sub" table="SUB"
        discriminator-value="hib_refresh1.Sub">
   
        <id name="id" column="SUB_ID">
            <generator class="native"/>
        </id>

        <discriminator column="CLASS" not-null="true" type="string"/>
        <property name="val" column="VAL" not-null="true"/>
        <many-to-one name="item" column="ITEM_ID" class="hib_refresh1.Item"/>
    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 5:59 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
wrong forum

_________________
Emmanuel


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.