[Hibernate-JIRA] Created: (HCANN-16) OneToOneSecondPass Metadata is mistakenly interpreted
by Claude Houle (JIRA)
OneToOneSecondPass Metadata is mistakenly interpreted
-----------------------------------------------------
Key: HCANN-16
URL: http://opensource.atlassian.com/projects/hibernate/browse/HCANN-16
Project: Hibernate Commons Annotations
Issue Type: Bug
Affects Versions: 3.1.0.GA
Reporter: Claude Houle
Attachments: hibernate-annotation-3.4.0.GA_3.4.0.1.GA.patch, unit-test.zip
I've been tracking an issue that has been causing us some trouble
regarding annotation-based hibernate mappings. The exception occurs at
run-time only:
/org.hibernate.PropertyValueException: not-null property references a
null or transient value ...
/
At first I believed we had an issue with our entity mapping was faulty
and went to try and figure it out... However, I came accross several
examples on the wide internet and showed that my mapping seems
correct. Furthermore, I had some other entities mapped in a similar
fashion that did not cause any issue... How could that be?
I traced the Hibernate code to a class named
org.hibernate.cfg.OneToOneSecondPass (Hibernate Annotations 3.4.0.GA
for those interested to look at the code) up to line 147:
...
Iterator it = otherSide.getJoinIterator();
Join otherSideJoin = null;
while ( it.hasNext() ) {
otherSideJoin = (Join) it.next();
if ( otherSideJoin.containsProperty( otherSideProperty ) ) {
break;
}
}
if ( otherSideJoin != null ) {
...
}
...
If you look closely, it seems that if there are JOINs but none
contains the otherSideProperty, the variable otherSideJoin will not be
null and will contains the last joins of the iterator even if it is
not valid.
The patched-up code would look like:
...
Iterator it = otherSide.getJoinIterator();
Join otherSideJoin = null;
while ( it.hasNext() ) {
Join otherSideJoinValue = (Join) it.next();
if ( otherSideJoinValue.containsProperty( otherSideProperty ) ) {
otherSideJoin = otherSideJoinValue;
break;
}
}
if ( otherSideJoin != null ) {
...
}
...
To fix my issue, I applied this patch:
Index: src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
===================================================================
--- src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
(revision 18572)
+++ src/main/java/org/hibernate/cfg/OneToOneSecondPass.java
(working copy)
@@ -146,8 +146,9 @@
Iterator it = otherSide.getJoinIterator();
Join otherSideJoin = null;
while ( it.hasNext() ) {
- otherSideJoin = (Join) it.next();
- if ( otherSideJoin.containsProperty(
otherSideProperty ) ) {
+ Join otherSideJoinValue = (Join) it.next();
+ if ( otherSideJoinValue.containsProperty(
otherSideProperty ) ) {
+ otherSideJoin = otherSideJoinValue;
break;
}
}
I compiled the code locally and re-tried my failing code and it worked
beautifully. it seemed that my last joins in the iterator has a
nullable = false which caused the runtime
/org.hibernate.PropertyValueException: not-null property references a
null or transient value/
If you take a look at the attached file unit-test.zip which contains a sample of code which reproduce the issue.
The other file attached contains the fixed I applied to the source-code to eliminate the problem
--
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
16 years, 2 months
[Hibernate-JIRA] Created: (HHH-2501) Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.
by Gunther Schadow (JIRA)
Read-only state of an entity in a session to propagate into subsequently lazy-loaded entities.
----------------------------------------------------------------------------------------------
Key: HHH-2501
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2501
Project: Hibernate3
Type: Improvement
Components: core
Environment: any
Reporter: Gunther Schadow
ISSUE:
Given an Entity entity and after Session.setReadOnly(entity), if the entity has lazy collections, lazy properties etc., other Entities are loaded into the Session upon navigating the object graph in the default read-writable state. However, it seems more reasonable to maintain the read-only state of the owning object.
REQUEST:
Ability to propagate read-only state of an entity in a session into other lazy-loaded entities.
BACKGROUND:
We have a system which permits users to make concurrent transactions which involve many of the same objects. Usually no changes happen on these shared objects, but instead connections (links) are made between these objects and new objects. For example, say you have an online meeting system, and every Meeting held has a link to a number of User object. The User objects are never changed in a Meeting, but there is a Relation called Participation (of User in Meeting) to which new relationships are added. When a new meeting is saved, it wants to save the User objects simply because a new Participation link entry was added to the collection.
To an extent we can prevent this from happening by setting the Users explicitly to read-only. However, now suppose we added a function "Invite your Friends" to a Meeting, in which we would simply go:
for(User friend : currentUser.getFriends())
meeting.addInvitation(friend);
Now an Invitation is like a Participation, and would be added into the User but now it wants to save these users just for a version upgrade only because they have received an Invitation.
--
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
16 years, 2 months