-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate Repeated column mapping problem complex table
PostPosted: Wed Jan 16, 2013 11:57 am 
Newbie

Joined: Thu Dec 17, 2009 11:43 am
Posts: 6
I have following table,

Code:
Table (
  col1 [PK, FK1, FK2],
  col2 [PK]
  col3 [FK2]
  col4
  col5
)

The primary key for table is composite. It is mapped using <composite-id> element in mapping file.

1. PK Mapping
Code:
<composite-id>
  <key-property column="col1" />
  <key-property column="col2" />
</composite-id>


2. FK1 mapping
Now col1 is foreign key so it is mapped again.
Code:
<many-to-one class="SomeClass" column="col1" />


3. FK2 mapping
There is also foreign key to composite primary key. It is mapped again,
Code:
<many-to-one ...>
  <column name="col1" />
  <column name="col3" />
</many-to-one>

Now col1 is mapped thrice and I get repeated column mapping exception. I can mark FK1 mapping as update='false' and insert='false' without any impact.

But if I mark FK2 mapping as update='false' and insert='false' then the col3 value is not inserted in DB and I lose the foreign key link. If I remove update='false' and insert='false' then I get mapping problem.

Is there any workaround for this issue? I cannot change the table structure also we are not using annotations.

Is it possible to define update='false' and insert='false' at column level, so that I can mark col1 in FK2 mapping.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.