Dear all,
I'm a new user of hibernate v4.0.1 final.
Recently I am trying to use hibernate to map to some tables of a legacy db.
The problem is the joined subclasses only have a part of the composite key of the base.
Base class:
Code:
@Entity
@Table(name="foo")
@Inheritance(strategy=InheritanceType.JOINED)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@IdClass(CompositeId.class)
public abstract class Foo implements Serializable {
@Id
@Column(name = "primkey")
private Long id;
@Id
@Column(name = "type")
private String type;
Composite key class:
Code:
public class CompositeId implements Serializable {
private Long id;
private String type;
Sub class with its own table but only one primary key:
Code:
@Entity
@Table(name="bar")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorValue("bartype")
@PrimaryKeyJoinColumn(name = "barkey", referencedColumnName = "primkey")
public class Bar extends Foo {
This is what I get:
Quote:
[INFO] [talledLocalContainer] Caused by: org.hibernate.AnnotationException: SecondaryTable JoinColumn cannot reference a non primary key
If I don't use a composite key in the base class I get undesired results.
Any ideas?
Of course I could adapt the tables of the subclasses so that the composite key can be properly mapped with @PrimaryKeyJoinColumns but I'd like to avoid this if possible.