-->
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: Compound Keys with doublicate FK columns
PostPosted: Sun Mar 25, 2007 8:38 pm 
Newbie

Joined: Sun Mar 25, 2007 9:16 am
Posts: 2
Hi,

does hibernate support to map 2 equal Java fields used as FK in a compound key into the same database column?
Both fields being fetched, but only one being inserted.

Code:
// Three simple entities A, B, C
@Entity class A {
    @Id String a;
}
@Entity class B {
    @Id String b;
}
@Entity class C {
    @Id String c;
}
// Two link tables A-B and A-C using compound keys
@Embeddable class AB_PK {
     A a;
     B b;
}
@Entity class AB {
    @Id AB_PK abPk;
}
@Embeddable class AC_PK {
    A a;
    C c;
}
@Entity class AC {
    @Id AC_PK acPk;   
}
// So far so good. But now it comes to define a link table between AB and AC,
// where both 'a' columns are identical and exist only once in the database
@Embeddable class ABAC_PK {
    AB ab;
    AC ac;
}
@Entity class ABAC {
    @Id ABAC_PK abacPk; // requires 4 columns a, b, a, c.
}


Is there any way to use the above defined ABAC_PK layout with a database table
which only contains a, b and c PK columns, but not column 'a' twice (with some other name).

In other words. Is there a way to map:
Code:
abacPk.ab.abPk.a.a
abacPk.ab.abPk.b.b
abacPk.ac.acPk.a.a // with same value as: abacPk.ab.abPk.a.a
abacPk.ac.acPk.c.c

into the three database columns a, b, c? Preferable via annotations.

I tried several @Column, @AttributeOverwrite combinations but wasn't able to manage this.

BTW: I know that I'm able to define ABAC_PK as:
Code:
@Embeddable class ABAC_PK {
    AB ab;
    String c;
}


Thanks,
Jürgen


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.