-->
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.  [ 2 posts ] 
Author Message
 Post subject: annotation: problem configuring join not in pk
PostPosted: Wed Mar 16, 2005 10:33 am 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
I try to use hibernate on an legacy database.
What I have done so far is I added two new columns "version" and "oid". OID is for the surrogation key and will be set by hibernate or by an trigger if the legacy application writes into the table.
The same for the "version" column.

Now I thought I have a perfect layout for use in hibernate. But ...

mytable.Art:
Code:
@Id(generate=GeneratorType.AUTO)
private Long oid;

@OneToMany(cascade=CascadeType.ALL)
@JoinColumns ({
    @JoinColumn(name = "CUST_ID", referencedColumnName = "CUST_ID"),
    @JoinColumn(name = "ART_ID", referencedColumnName = "ART_ID")
})
private Set<mytable.ArtDoc> docs;


mytable.ArtDoc:
Code:
@Id(generate=GeneratorType.AUTO)
private Long oid;

@ManyToOne()
@JoinColumns ({
    @JoinColumn(name = "CUST_ID", referencedColumnName = "CUST_ID"),
    @JoinColumn(name = "ART_ID", referencedColumnName = "ART_ID")
})
private Art art;


For sure, there are a punch of other columns too, but I think we could ignore them now.

Well, during creation of the sessionFactory I get the exception beneath.

Is it really needet to have the columns of the joined tables in the primary key?


Hibernate version:

3.0rc
annotations 3.0 alpha 3

Mapping documents:

Full stack trace of any exception that occurs:
Caused by: org.hibernate.AnnotationException: @JoinColumns with 2 columns refers to mytable.Art which has a 1 sized PK
at org.hibernate.cfg.AnnotationBinder.bindFk(AnnotationBinder.java:1080)
at org.hibernate.cfg.AnnotationBinder.bindFkSecondPass(AnnotationBinder.java:1074)
at org.hibernate.cfg.FkSecondPass.secondPass(FkSecondPass.java:32)
at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:27)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:110)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1044)


Name and version of the database you are using:

oracle 9


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 16, 2005 4:13 pm 
Regular
Regular

Joined: Thu Dec 11, 2003 4:14 pm
Posts: 86
Location: Hibernate 3 + annotations, Oracle 9i, PostgreSQL 8.0, Java 1.5.0
Oh boy!

After reading and reading and much more reading it looks like I answered it myself:

http://www.hibernate.org/hib_docs/annotations/
Quote:
The current implementation does not support the referencedColumnName attribute , so Hibernate will join to the primary key


I dont know how often I read the document ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.