Hibernate version: 3.2.1.ga
I have the following entities:
@Entity
@Table(name="CS_CODIF")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="CODIF_GROUP", discriminatorType=DiscriminatorType.STRING)
public abstract class Codif {
@Id
@GeneratedValue
@Column(name = "ID")
private Long id;
@Column(name="CODE", nullable=false)
private String code;
@Column(name="LABEL", nullable=false)
private String label;
}
@Entity
@DiscriminatorValue("SECTOR_A")
public class SectorA extends Codif {
}
@Entity
@DiscriminatorValue("SECTOR_B")
public class SectorB extends Codif {
}
@Entity
@Table(name = "CS_INSTRUMENT")
public class Instrument {
@Id
@GeneratedValue
@Column(name = "ID")
private Long id;
@ManyToOne(targetEntity = Codif.class, optional = false)
@JoinColumn(name="SECTOR_A", referencedColumnName="CODE", nullable=false)
private ISectorA sectorA;
}
In the latter entity, I specified in the ManyToOne relation the class
Codif as target entity (targetEntity = Codif.class). This example works
fine but doesn't fit to my needs: I want to make sure that if there are
two entities from type SectorA and SectorB with the same CODE, only the
one from type SectorA will be read.
Now, if I replace
@ManyToOne(targetEntity = Codif.class, optional = false)
@JoinColumn(name="SECTOR_A", referencedColumnName="CODE", nullable=false)
private ISectorA sectorA;
by
@ManyToOne(targetEntity = SectorA.class, optional = false)
@JoinColumn(name="SECTOR_A", referencedColumnName="CODE", nullable=false)
private ISectorA sectorA;
I get the following exception:
"org.hibernate.AnnotationException: referencedColumnNames(CODE) of
...Instrument.sectorA referencing ...SectorA not mapped to a single property"
What I understand is that SectorA class doesn't inherit from "CODE" property
of Codif class.
So, I add the annotation @MappedSuperclass to the superclass Codif.
But the result is that hibernate tries to create a "SectorA" table, which is
against SINGLE_TABLE inheritance strategy. Is this the expected behavior?
Thanks for your help,
Regards,
Nicolas
|