[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-5695) Hibernate complains about an unknown mappedBy property when mapping a bidirectional OneToOne relation with a derived identifier
Gail Badner (JIRA)
noreply at atlassian.com
Thu Jan 13 18:29:05 EST 2011
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5695?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39613#action_39613 ]
Gail Badner commented on HHH-5695:
----------------------------------
After applying the fix proposed for HHH-5359, this issue is not resolved.
I get errors with the following:
1) @OneToOne(mappedBy="foo", cascade=CascadeType.ALL)
private Bar bar;
which throws java.lang.StackOverflowError because: Bar is loaded first, in the process of resolving Bar.foo, an attempt is made to eagerly load foo.bar, which tries to resolve foo.bar.foo, etc.
2) @OneToOne(mappedBy="foo", optional=true, cascade=CascadeType.ALL)
private Bar bar;
which throws org.hibernate.exception.ConstraintViolationException
Caused by: org.h2.jdbc.JdbcBatchUpdateException: Referential integrity constraint vi
olation: "FK103F322D7D08D: PUBLIC.BAR FOREIGN KEY(BAR_ID) REFERENCES PUBLIC.FOO
(ID)"; SQL statement:
insert into Bar (details, BAR_ID) values (?, ?) [23002-145]
3) @OneToOne(mappedBy="foo", cascade=CascadeType.ALL)
@MapsId
private Bar bar;
java.util.NoSuchElementException
at java.util.AbstractList$Itr.next(AbstractList.java:350)
at org.hibernate.util.JoinedIterator.next(JoinedIterator.java:76)
at org.hibernate.cfg.annotations.TableBinder.linkJoinColumnWithValueOverridi
ngNameIfImplicit(TableBinder.java:494)
at org.hibernate.cfg.PkDrivenByDefaultMapsIdSecondPass.doSecondPass(PkDriven
ByDefaultMapsIdSecondPass.java:55)
at org.hibernate.cfg.Configuration.processSecondPassesOfType(Configuration.j
ava:1424)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1386
)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:18
26)
Emmanuel, Hardy, is this a valid test case?
The test is included in https://github.com/hibernate/hibernate-core/pull/31
> Hibernate complains about an unknown mappedBy property when mapping a bidirectional OneToOne relation with a derived identifier
> -------------------------------------------------------------------------------------------------------------------------------
>
> Key: HHH-5695
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5695
> Project: Hibernate Core
> Issue Type: Bug
> Components: entity-manager
> Affects Versions: 3.5.0-Final, 3.5.1, 3.5.2, 3.5.3, 3.5.4, 3.6.0.Beta1, 3.6.0.Beta2, 3.5.5, 3.6.0.Beta3, 3.6.0.Beta4, 3.5.6, 3.6.0.CR1, 3.6.0.CR2, 3.6.0
> Environment: Hibernate 3.5+, any database.
> Reporter: Pascal Thivent
> Assignee: Gail Badner
> Fix For: 3.6.1, 4.0.0.Alpha1
>
> Attachments: HHH-5695.zip
>
>
> I have a OneToOne mapping between Foo and Bar where Bar uses a derived identifier. So Bar is the "dependent" entity and has a single primary key attribute which is mapped by the relationship attribute (i.e. using `Id` on the `OneToOne` relationship).
> Foo is mapped like this:
>
> {code}
> @Entity
> public class Foo {
> @Id @GeneratedValue
> private Long id;
> private String name;
> @OneToOne(mappedBy="foo", cascade=CascadeType.ALL)
> private Bar bar;
> public Long getId() {
> return id;
> }
> //...
> }
> {code}
> and Bar:
> {code}
> @Entity
> public class Bar {
> @Id
> @OneToOne
> @JoinColumn(name="BAR_ID")
> private Foo foo;
> //...
> }
> {code}
> This mapping is described in the section 2.4.1.2 of the JPA 2.0 specification, Example 4, case (a) and works with the RI (run {{mvn test -Peclipselink,h2}} on the attached project).
> However, Hibernate fails to initialize and complains about the mappedBy attribute:
> {code}
> Caused by: org.hibernate.AnnotationException: Unknown mappedBy in: com.acme.Foo.bar, referenced property unknown: com.acme.Bar.foo
> at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:159)
> at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1686)
> at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1393)
> at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1345)
> at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1477)
> at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1096)
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:278)
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:362)
> ... 24 more
> {code}
> Run {{mvn test}} to reproduce.
--
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