[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-199) Polymorphic association to a MappedSuperclass throws exception

Don Tam (JIRA) noreply at atlassian.com
Mon Apr 13 12:28:18 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-199?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32855#action_32855 ] 

Don Tam commented on EJB-199:
-----------------------------

I don't think TABLE_PER_CLASS is really ideal for this considering the restrictions (bi-directional associations only). What would be ideal, actually, is if AssociationOverride could also override the the targetEntity attribute of the association.

So:

@MappedSuperclass
public abstract class A {}

@Entity
public class B extends A{}

@MappedSuperclass
public abstract class C {
  private A a;
  @ManyToOne
  public A getA() { return a; }
}

@Entity
@AssociationOverride(name="a", targetEntity=B.class)
public class D extends C {
}

> Polymorphic association to a MappedSuperclass throws exception
> --------------------------------------------------------------
>
>                 Key: EJB-199
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-199
>             Project: Hibernate Entity Manager
>          Issue Type: Bug
>          Components: EntityManager
>    Affects Versions: 3.2.0.cr1
>         Environment: Annotations CR1, EntityManager CR1, and Hibernate 3.2 CR2
>            Reporter: Markus Junginger
>
> I think it should be possible to have polymorphic association to a class annotated as a MappedSuperclass. However, this combination throws an exception.
> The class Xyz is a super class for a couple of entity classes:
> @MappedSuperclass
> public abstract class Xyz{...}
> The following association to Xyz does not work (see exception below)
> @ManyToOne(fetch = FetchType.LAZY)
> @JoinColumns({...})
> private Xyz test;
> If it matters, each entity (the sub classes of Xyz) is annotated with
> @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS).
> Here's the execption:
> javax.persistence.PersistenceException: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on play.abc.test references an unknown entity: play.Xyz
> at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:196)
> at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:114)
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:37)
> at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:27)
> ...
> Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on play.abc.test references an unknown entity: play.Xyz
> at org.hibernate.cfg.FkSecondPass.doSecondPass(FkSecondPass.java:40)
> at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:261)
> at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1034)
> at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:868)
> at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:163)
> at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:641)
> at org.hibernate.ejb.Ejb3Configuration.createFactory(Ejb3Configuration.java:134)
> at org.hibernate.ejb.Ejb3Configuration.createEntityManagerFactory(Ejb3Configuration.java:188)
> ... 20 more

-- 
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