[hibernate-issues] [Hibernate-JIRA] Created: (HHH-5925) Use Hibernate.isInitialized() in Parent/Child example
Robert Wruck (JIRA)
noreply at atlassian.com
Sun Feb 13 07:55:05 EST 2011
Use Hibernate.isInitialized() in Parent/Child example
-----------------------------------------------------
Key: HHH-5925
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5925
Project: Hibernate Core
Issue Type: Improvement
Components: documentation
Affects Versions: 3.6.1
Environment: doesn't matter
Reporter: Robert Wruck
Priority: Trivial
In chapter 24.2 (Example: Parent/Child, Bidirectional one-to-many) it is suggested to use an addChild method defined as:
public void addChild(Child c) {
c.setParent(this);
children.add(c);
}
This leads to bad performance as children.add will always initialize a lazy collection even if it doesn't have to.
A more efficient solution would be
public void addChild(Child c) {
c.setParent(this);
if (Hibernate.isInitialized(children))
children.add(c);
}
which only adds the child to the inverse collection if needed to ensure consistency.
--
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