-->
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: referencedColumnNames not mapped to a single property
PostPosted: Sun Dec 25, 2011 4:42 am 
Newbie

Joined: Sun Dec 25, 2011 4:31 am
Posts: 2
Location: Bern, Switzerland
I'm mapping a legacy read-only database.

I have two tables A and B

  • A with a multiple column primary key (ID and ID2)
  • B with a multiple column primary key (ID and ID3)

A row in A can reference several rows in B (B.ID = A.ID) and a row in B can be referenced by several rows in A.

It is basically a many-to-many relationship without a join table. Since I just have to read the tables, I tried with two one-to-many relationships in both classes.

The additional problem that I have is that both IDs used for the join are not the primary key.

I have the following classes:

Code:
@Entity
@Table( name = "A" )
@IdClass( PrimaryKeysA.class )
public class A {

    @Id
    @Column( name = "ID", insertable = false, updatable = false, columnDefinition = "char" )
    private String id;

    @Id
    @Column( name = "ID2", insertable = false, updatable = false )
    private int id2;

    @OneToMany( cascade = CascadeType.ALL )
    @JoinColumn( name = "ID", columnDefinition = "char", referencedColumnName = "ID" )
    private Set< B > setOfBs;

}

@Entity
@Table( name = "B" )
@IdClass( PrimaryKeysB.class )
public class B {

    @Id
    @Column( name = "ID", insertable = false, updatable = false, columnDefinition = "char" )
    private String id;

    @Id
    @Column( name = "ID3", insertable = false, updatable = false )
    private int id3;

    @OneToMany( cascade = CascadeType.ALL )
    @JoinColumn( name = "ID", columnDefinition = "char", referencedColumnName = "ID" )
    private Set< A > setOfAs;

}


Hibernate generates the following error:

Code:
Exception while preparing the app : referencedColumnNames(ID) of package.B referencing package.A not mapped to a single property


I agree with the message: B.ID is referencing only a part of the primary key of A. But why is this a problem?


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.