Hi,
I'm using Hibernate 3.2.0 with Hibernate Annotation 3.3.0GA.
Suppose I've got the following code
Code:
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name="mediaclasstype",
discriminatorType=DiscriminatorType.STRING
)
public abstract class AbstractMedia
{
@Id
@GeneratedValue
private int id;
}
@Entity
@SecondaryTable(name = "media", pkJoinColumns = { @PrimaryKeyJoinColumn(name = "id", referencedColumnName = "id") })
public class Media
{
@OneToOne( optional=false, cascade = { CascadeType.ALL } )
@Cascade( { org.hibernate.annotations.CascadeType.ALL } )
@JoinColumn( table="media", name="id" )
private Revision revision = new Revision(this);
}
@Entity
public class Revision
{
@Id
@GeneratedValue
private int id;
@Column
private int number;
}
The problem is that the foreign key constraint is always created in the abstractmedia table instead of the media table. This poses a problem because there's another subclass of abstractmedia which doesn't have a revision. Also I have to keep all the classes in one table, because I need to store one attribute of abstractmedia in a separate table (using SecondaryTable, which doesn't work with the other inheritance strategies).
Any idea how I can tell Hibernate to create the foreign key on the media table instead of the abstractmedia table?
[/code]