[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3798?page=c...
]
Ronald Kurz commented on HHH-3798:
----------------------------------
First I thought it's a problem with an entity in an OneToMany and a ManyToOne mapping
at the same time. But I wrote a test case (see attachment test-case2.tar.gz) with the most
simplest possible parent-child mapping. Unless I didn't got the concept of lazy
loading totally wrong, this really should work!
@Entity
public class ParentLazy {
@Id
public Integer id;
@OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "childId")
public Child child;
}
@Entity
public class Child {
@Id
public Integer id;
}
Summary of test 'testLazy':
1 create Child(CHILD_ID)
2 save Child
3 create ParentLazy(PARENT_ID)
4 attach created Child
5 save ParentLazy
6 flush & clear session
assertEquals(CHILD_ID, ((ParentLazy) session.get(ParentLazy.class, PARENT_ID)).child.id);
// fails with child.id == null
The eager version of this test works as expected:
@Entity
public class ParentEager {
@Id
public Integer id;
@OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "childId")
public Child child;
}
... the same 6 steps using the ParentEager entity
assertEquals(CHILD_ID, ((ParentEager) s.get(ParentEager.class, PARENT_ID)).child.id); //
succeeds
test-case2 is a test case written for the annonations project,
tested against: svn info
URL:
http://anonsvn.jboss.org/repos/hibernate/core/trunk
Repository Root:
http://anonsvn.jboss.org/repos/hibernate
Revision: 16125
failure to lazy load a manyToOne and oneToMany mapped entity
------------------------------------------------------------
Key: HHH-3798
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-3798
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.3.1, 3.5
Environment: hibernate annotations test case, maven profile hsqldb, svn rev
16079
hibernate-core 3.3.1.GA, JBoss 4.2.3, SQLServer 2000
Reporter: Ronald Kurz
Attachments: test-case.tar.gz, test-case2.tar.gz
Following situtation: an entity Data has Revision entities (oneToMany). Each Revision
entity belongs to a Data entity. The Data entity has one manyToOne mapping to the current
Revision. The mappings from Data to Revision are all lazy.
When loading a Data entity, which has two Revisions, the Revision entity which is also
mapped as manyToOne (the current Revision for that Data entity), does not get loaded. It
will be an uninitialized proxy, which is also resistent to
Hibernate.initialize(<Data>.revision). The same proxy is also in the oneToMany
mapped list.
@Entity
public class Data {
@Id @GeneratedValue
public int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "revisionId")
public Revision revision;
@OneToMany(mappedBy = "data")
public List<Revision> revisions = new ArrayList<Revision>();
}
@Entity
public class Revision {
@Id @GeneratedValue
public int id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "dataId", nullable = false, updatable = false)
public Data data;
public Integer number;
}
The test case is written for the hibernate-annotations project (simply because I never
wrote a mapping using xml)
--
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