pb00067 wrote:
Use @OneToMany
If you want to have the relation bidirectional, then you additionally must define the mappedBy property.
I'm using @OneToMany with mapped by, but getting this error:
Exception in thread "main" org.hibernate.MappingException: Foreign key (FKC131381C3D434C46:journals [journalized_type,journalized_id])) must have same number of columns as the referenced primary key (issues [id])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:113)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:96)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1310)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1217)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
My classes are:
@Entity
@Table(name="journals")
public class Journal {
@Id
private Integer id;
@Any(metaColumn = @Column(name = "journalized_type"))
@AnyMetaDef(idType = "integer",
metaType = "string",
metaValues = { @MetaValue(value = "Issue", targetEntity = Issue.class), //@MetaValue(value = "Board", targetEntity = Board.class) }
)
@JoinColumn(name="journalized_id")
private Journalized journalized;
...
@Entity
@Table(name="issues")
public class Issue implements Journalized {
@Id
private Integer id;
@OneToMany(mappedBy="journalized")
//@Where(clause="journalized_type = 'Issues'")
private List<Journal> journals;
...
Any ideas?