-->
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: problem referring to child entity with SINGLE_TABLE strategy
PostPosted: Mon Sep 03, 2007 1:51 pm 
Newbie

Joined: Mon Sep 03, 2007 1:16 pm
Posts: 1
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


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.