[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4320) Bidirectional Polymorphism
Bruno Medeiros (JIRA)
noreply at atlassian.com
Mon Dec 27 13:45:05 EST 2010
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4320?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39434#action_39434 ]
Bruno Medeiros commented on HHH-4320:
-------------------------------------
I'm trying to do the same without success.
My code:
@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;
...
The error I got is:
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)
Of course there is no way to create foreign keys, We need a @OneToAny annotation. Is there any way to workaround that?
> Bidirectional Polymorphism
> --------------------------
>
> Key: HHH-4320
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4320
> Project: Hibernate Core
> Issue Type: New Feature
> Components: annotations
> Environment: 3.4.0.GA, Any database
> Reporter: Yong Joo Jeong
>
> I'm trying to implement bidirectional polymorphic class.
> Code:
> public class Order{
> ...
> @Any( metaColumn = @Column( name = "item_type" ), fetch=FetchType.EAGER )
> @AnyMetaDef(
> idType = "long",
> metaType = "string",
> metaValues = {
> @MetaValue( value = "ItemA", targetEntity = ItemA.class ),
> @MetaValue( value = "ItemB", targetEntity = ItemB.class )
> } )
> @JoinColumn( name = "item_id" )
> Object item;
> ...
> }
> And trying to do somthing like the following
> Code:
> public class ItemA {
> @OneToAny // like @OneToMany; in Order table there are "item_id" and "item_type" fields to distinguish ItemA and ItemB
> List<Order> orders;
> ...
> }
> RoR support this kind of relationship, but I can't find it from Hibernate.
> Inheritance with "Table per class" is not an option since it does not support the IDENTITY generator strategy.
> Any solution for this?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list