-->
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: In hbm file, creating a set with multiple key columns
PostPosted: Mon Sep 01, 2008 2:08 am 
Newbie

Joined: Mon Sep 01, 2008 1:58 am
Posts: 3
Dear All,

I have a question on mapping of database in hbm file.

I have a table A, it cosists of 2 primary key
table B is a many to one relationship to table A

Therefore Table B will have 3 primary key.

I tried to insert following code in table B's hbm file

<set name="tableBSet" cascade="all" inverse="true">
<key column="tableAPrimaryKey1"/>
<key column="tableAPrimaryKey2"/>
<one-to-many class="tableB"/>
</set>

Some error with the multiple keys?

14:08:51,906 ERROR [XMLHelper:61] Error parsing XML: XML InputStream(15) The content of element type "set" must match "(meta*,subselect?,cache?,synchronize*,comment?,key,(element|one-to-many|many-to-many|composite-element|many-to-any),loader?,sql-insert?,sql-update?,sql-delete?,sql-delete-all?,filter*)".

how should i correct the mapping?
Thanks for your kind assistance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2008 3:26 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
The <key> tag can have multiple <column> subtags. Something like this may work:

Code:
<set name="tableBSet" cascade="all" inverse="true">
   <key>
      <column name="tableAPrimaryKey1"/>
      <column name="tableAPrimaryKey2"/>
   </key>
<one-to-many class="tableB"/>
</set>



See http://www.hibernate.org/hib_docs/v3/re ... ompositeid for a lot of examples.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 01, 2008 4:26 am 
Newbie

Joined: Mon Sep 01, 2008 1:58 am
Posts: 3
Thanks, i have tried your method and it works.

However, i face a new problem now.

from the "one" side TableA, i use the following:
<set name="tableBSet" cascade="all" inverse="true">
<key>
<column name="tableAPrimaryKey1"/>
<column name="tableAPrimaryKey2"/>
</key>
<one-to-many class="TableB"/>
</set>

from the "many" side TableB, i use the following:

<composite-id>
<key-many-to-one name="tableA" class="TableA">
<column name="tableAPrimaryKey1"/>
<column name="tableAPrimaryKey2"/>
</key-many-to-one>
<key-property name="tableB" type="java.lang.String" column="tableB"/>
</composite-id>

suppose the field type are
tableAPrimaryKey1 => timestamp
tableAPrimaryKey2 => string

The mapping actually does
tableAPrimaryKey1 => string
tableAPrimaryKey2 => timestamp

is there anything i can add in to ensure the types can be correctly assigned by the mapping ?


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.