[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4975?page=c...
]
Stefan du Fresne commented on HHH-4975:
---------------------------------------
bq. This will work only for one level in the subclassing hierarchy, what if we have more
then one level ?
I am having this same problem. We have the following type of structure:
{noformat}
@MappedSuperclass
public abstract class AbstractBean {
protected Long versionNumber;
....
@MappedSuperclass
public abstract class AbstractFoo extends AbstractBean {
protected Long fooId;
@Entity
@Table(...)
public class Foo extends AbstractFoo {
.....
{noformat}
And are trying to pull in a Foo like this:
{noformat}
@ManyToOne
@JoinColumns({ @JoinColumn(name = "versionNumber", referencedColumnName =
"versionNumber"),
@JoinColumn(name = "fooId", referencedColumnName = "fooId") })
protected Foo foo;
{noformat}
Unfortunately the only way of solving it I have found so far is to pull all the necessary
fields into one of the classes, e.g.:
{noformat}
@MappedSuperclass
public abstract class AbstractFoo extends AbstractBean {
protected Long fooId;
@Column(name = "versionNumber"}
protected Long justHereForMappingMagic; // Named something different so the compiler
doesn't complain
{noformat}
And then mapping explicitly to that class:
{noformat}
@ManyToOne(targetEntity = AbstractFoo.class)
@JoinColumns({ @JoinColumn(name = "versionNumber", referencedColumnName =
"versionNumber"),
@JoinColumn(name = "fooId", referencedColumnName = "fooId") })
protected Foo foo;
{noformat}
ManyToOne and referencedColumnName and MappedSuperclass (2 Levels)
=> org.hibernate.AnnotationException: referencedColumnNames ... not mapped to a single
property
------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-4975
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4975
Project: Hibernate Core
Issue Type: Bug
Components: annotations
Affects Versions: 3.3.2
Environment: Hibernate version 3.3.2.GA, HSQLDB 1.8.0.10
Reporter: Christian Fritschi
Priority: Critical
Attachments: startTestDb.rar, ukMapping.rar, UkMappingTest.java
Level 1 (superClass)
-------
@MappedSuperclass
public abstract class AbstractMasterUk ...
@Id
private int id;
....
@Column(name="MASTER_ID", nullable = false, length=50)
private String masterId;
Level 2 (superClass)
-------
@Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@Table(name="MASTER_UK")
@DiscriminatorColumn(name="DOMAIN",
discriminatorType=DiscriminatorType.STRING)
public class MasterUkBase extends AbstractMasterUk ....
Parent-Class
------------
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@DiscriminatorValue(MasterUk1.DOMAIN)
public class MasterUk1 extends MasterUkBase ...
Child-Class
-----------
@Entity
@Table(name="DETAIL_UK")
public class DetailUk implements Serializable {
@Id
private int id;
@ManyToOne(optional=false)
@JoinColumn(name="MASTER", nullable=true,
referencedColumnName="MASTER_ID")
private MasterUk1 master;
Result:
org.hibernate.AnnotationException: referencedColumnNames(MASTER_ID) of
annotations.playground.delta.ukMapping.DetailUk.master referencing
annotations.playground.delta.ukMapping.MasterUk1 not mapped to a single property
at
org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:180)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:88)
at
org.hibernate.cfg.AnnotationConfiguration.processEndOfQueue(AnnotationConfiguration.java:456)
at
org.hibernate.cfg.AnnotationConfiguration.processFkSecondPassInOrder(AnnotationConfiguration.java:438)
at
org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:309)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
at
org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
.....
--
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....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira