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