-->
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: Map with a key column from composite-element
PostPosted: Thu Mar 01, 2007 7:00 pm 
Newbie

Joined: Thu Mar 01, 2007 6:52 pm
Posts: 4
Location: Kraków, Poland
I have three tables in the database:

Code:
order (id,...)
shape(id, ...)
order_has_shape(order_id, shape_id, value)


On the 'order' side I created a mapping of the collection of shapes as follows:

Code:
<class name="pl.hefajstos.core.model.Order" table="`order`">
       
    ...
       
    <map name="shapes" table="order_has_shape">
        <key column="order_id"/>
        <map-key column="shape_id" type="long"/>
        <composite-element class="pl.hefajstos.core.model.OrderedShape">
            <property name="amount" not-null="true"/>
            <many-to-one name="shape" class="pl.hefajstos.core.model.Shape" column="shape_id"/>
        </composite-element>
    </map>
</class>


Unfortunately Hibernate doesn't like this telling me:

Code:
org.hibernate.MappingException: Repeated column in mapping for collection: pl.hefajstos.core.model.Order.shapes column: shape_id


What I want is having (on the Order side) the collection of shapes put into a map, key of which would be the values from shape_id column.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 7:35 pm 
Newbie

Joined: Thu Mar 01, 2007 6:52 pm
Posts: 4
Location: Kraków, Poland
Never mind...

Code:
<map-key formula="shape_id"...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 02, 2007 2:54 pm 
Newbie

Joined: Thu Mar 01, 2007 6:52 pm
Posts: 4
Location: Kraków, Poland
OK, that works but brings a question - what if I add to the map a newly created Shape object, without an ID yet? What ID would be assigned? A generic one from the map or would Hibernate persist the object and return an appropriate ID as its key?


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.