-->
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.  [ 7 posts ] 
Author Message
 Post subject: Map key and index as a part of the composite-element
PostPosted: Wed May 26, 2004 4:26 am 
Newbie

Joined: Wed May 26, 2004 4:16 am
Posts: 7
I need to map the key and index of the <map> to the properties of the composite-element.

For instance, I'm mapping a history of object state changes. I have two tables, "Object" and "ObjectState". States history is mapped as <map>, with object_id as key and start_date, end_date pair as a composite index.

The problem is that each object state is identified by objectId and startDate property, and I have to use them in equals() and hashCode(). How do I map key and index to the properties of the composite element?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 5:53 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I have absolutely no idea what you are talking about ...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 7:05 am 
Newbie

Joined: Wed May 26, 2004 4:16 am
Posts: 7
OK.

class MyObject {
long id;
SortedMap history;
}


class MyObjectState {
long key;
Date start;
int value1;
int value2;
int value3;

public boolean equals(Object o) {
return key==o.key && start.equals(o.start);
}
}

<class name="MyObject" table="object">
<id name="id" type="long" column="id" access="field"/>
<map name="history" class="MyObjectState" table="object_history">
<key column="object_id"/>
<index column="start_date"/>
<composite-element>
<property name="value1" column="value1"/>
<property name="value2" column="value2"/>
<property name="value3" column="value3"/>
</composite-element>
</map>
</class>

I need to map values of MyObjectState.key and MyObjectState.start to the object_history.object_id and object_history.start_date to make MyObjectState.equals(...) work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 7:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Try mapping it as another property of the composite-element with insert=false update=false


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 7:22 am 
Newbie

Joined: Wed May 26, 2004 4:16 am
Posts: 7
net.sf.hibernate.MappingException: insert="false", update="false" not supported for properties of components


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 7:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well can't map it then probably. Maybe rethink your model.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 26, 2004 7:40 am 
Newbie

Joined: Wed May 26, 2004 4:16 am
Posts: 7
Thanks anyway.


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