When defining a
@OneToOne association inside an @Embeddable object I've encountered an exception: org.hibernate.AnnotationException:
Illegal attempt to define a @JoinColumn with a mappedBy association (find example code and full stacktrace below)
According to the manual (
http://www.hibernate.org/hib_docs/annot ... ntity.html) Hibernate extends JPA spec and allows such definitions.
What am I missing here?
thanks in advance
Bregg
Libs used:
- hibernate3-3.2.3.GA.jar
- hibernate-annotations-3.2.0.GA.jar
- ejb3-persistence-1.0.1.GA.jar
Example code:
Code:
@Entity
public class Part {
...
@Id
@Column(name="PART_ID")
public long getPart() { ... }
}
@Embeddable
public class Inner {
...
@OneToOne
public Part getPart() { ... }
}
@Entity
public class Outer {
...
@Id
@Column(name="OUTER_ID")
public long getId() { ... }
@Embedded
@AssociationOverride(name="part", joinColumns=@JoinColumn(name="OUTER_PART_ID", referencedColumnName = "PART_ID"))
public Inner getInner() { ... }
}
Stacktrace:
org.hibernate.AnnotationException: Illegal attempt to define a @JoinColumn with a mappedBy association: inner.part
at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumn(Ejb3JoinColumn.java:152)
at org.hibernate.cfg.Ejb3JoinColumn.buildJoinColumns(Ejb3JoinColumn.java:127)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1110)
at org.hibernate.cfg.AnnotationBinder.fillComponent(AnnotationBinder.java:1662)
at org.hibernate.cfg.AnnotationBinder.bindComponent(AnnotationBinder.java:1599)
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1480)
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:706)
at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:452)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:268)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
...