[Hibernate-JIRA] Created: (HHH-3884) NPE with mutable Natuarl Id's
by Michael Kopp (JIRA)
NPE with mutable Natuarl Id's
-----------------------------
Key: HHH-3884
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3884
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.2.2
Reporter: Michael Kopp
When saving an entity with a mutable natural id hibernate throws the following NPE.
java.lang.NullPointerException
at org.hibernate.engine.StatefulPersistenceContext.getNaturalIdSnapshot(StatefulPersistenceContext.java:267)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:78)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:162)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:113)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:196)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
I checked the code and found the reason:
- getNaturalIdSnapshot calls getDatabaseSnapshot and checks the result for NO_ROW but not for null
- getDatabaseSnapshot will never return NO_ROW but null if nothing was found
hence getNaturalIdSnapshot will produce a NPE if the entity is not in the database already.
the fix is simple:
change:
Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
if ( entitySnapshot == NO_ROW ) {
return null;
}
to
Object[] entitySnapshot = getDatabaseSnapshot( id, persister );
if ( entitySnapshot == null ) {
return null;
}
This is still there in trunk as well!
--
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
14 years, 10 months
[Hibernate-JIRA] Resolved: (HHH-1574) AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids (Alex Burgel)
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574?page=c... ]
Gail Badner resolved HHH-1574.
------------------------------
Resolution: Fixed
Fixed in trunk and Branch_3_5.
Alex, thanks for the fix and the test case!
There may be a similar issue with immutable natural IDs containing a component. If someone runs into that, please open a new issue.
> AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids (Alex Burgel)
> ----------------------------------------------------------------------------------------------------
>
> Key: HHH-1574
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574
> Project: Hibernate Core
> Issue Type: Patch
> Affects Versions: 3.1.2
> Reporter: Alex Burgel
> Assignee: Gail Badner
> Fix For: 3.5.2, 3.6
>
> Attachments: resolveentity.patch, resolveentity32.patch, testcase.zip
>
>
> i just upgraded from 3.0.5 to 3.1.2, and i started seeing this problem. i'm not exactly sure where the bug is here, but this is what i'm seeing:
> i have a class, Subscription, which has a natural-id of class Subscriber and Edition (excerpts of relevant mapping files below).
> when Subscription is unloaded, if i make a change, then commit the session, i see this exception:
> HibernateException: immutable natural identifier of an instance of Subscription was altered
> this gets thrown from DefaultFlushEntityEventListener.checkNaturalId() line 80.
> i traced through that method, this is what happens:
> 1. in checkNaturalId, loaded == null , so getNaturalIdSnapshot() is called
> 2. this ends up generating some sql that selects the SubscriptionId and EditionId from the Subscription row.
> 3. the sql is generated in AbstractEntityPersister.getNaturalIdentifierSnapshot(), which calls hydrate for each returned column of the natural-id,
> 4. but hydrate only returns the id, instead of the actual entity
> 5. so this array of ids (instead of entities) ends up back in DefaultFlushEntityEventListener.checkNaturalId() as 'loaded', which gets compared to 'current'
> the trouble is that 'current' contains the entities, but 'loaded' only contains the ids of those entites, so the natural-id check fails, and i get the exception.
> this only happens when 'loaded' is null in checkNaturalId().
> the javadocs for hydrate say you have to call "resolve" afterwards... this isn't being done, so maybe thats the fix. if the natural-id is not just simple properties, then resolve should also be called.
> <class name="Subscription" table="Subscriptions" batch-size="10">
> <id name="id" column="Id" type="int"><generator class="native" /></id>
> <natural-id>
> <many-to-one name="subscriber" class="Subscriber" column="SubscriberId" />
> <many-to-one name="edition" class="Edition" column="EditionId" />
> </natural-id>
> ....
> </class>
> <class name="Subscriber" table="Subscriber">
> <id name="id" column="id" type="int"><generator class="native" /></id>
> <map name="subscriptions" inverse="true" cascade="all,delete-orphan" batch-size="10">
> <key column="SubscriberId" />
> <map-key-many-to-many column="EditionId" class="Edition" />
> <one-to-many class="Subscription" />
> </map>
> </class>
--
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
14 years, 10 months
[Hibernate-JIRA] Created: (HHH-4971) Findbugs Warnings
by Marco Tulio Valente (JIRA)
Findbugs Warnings
-----------------
Key: HHH-4971
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4971
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0.Beta-1
Reporter: Marco Tulio Valente
Priority: Minor
Dear all,
We are conducting a study about the relevance of the warnings reported by the FindBugs tool when executed over several open-source systems.
Particularly, in the case of Hibernate, we would like to confirm the relevance of the following warning reported by the tool (for version 3.5.0.beta1):
Location: org.hibernate.engine.StatefulPersistenceContext getNaturalIdSnapshot - Line: 298
Warning: Using pointer equality to compare different types. The method uses using pointer equality to compare two references that seem to be of different types. The result of this comparison will always be false at runtime.
Since this warning seemed relevant to us, we would like to confirm our classification with Hibernate's developers.
Best regards,
Marco Tulio Valente
Brazil
--
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
14 years, 10 months
[Hibernate-JIRA] Created: (HHH-2041) Update with unaltered natural-id fails
by Jim Pease (JIRA)
Update with unaltered natural-id fails
--------------------------------------
Key: HHH-2041
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2041
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.1.3
Environment: hibernate-3.1.3, mysql-4.1.12
Reporter: Jim Pease
This may be a duplicate of http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574.
Getting following error:
caused by: org.hibernate.HibernateException: immutable natural identifier of an instance of edu.syr.lsb.gmt.impl.LinkImpl was altered
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkNaturalId(DefaultFlushEntityEventListener.java:80)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:155)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:106)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:195)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:76)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
...
This is occurring without modifications to the natural identifier, which is mapped as follows:
<natural-id>
<property name="activityRef" column="ACTIVITY_REF" length="255" not-null="true" />
<many-to-one name="goal" class="GoalImpl" column="GOAL_ID" not-null="true" cascade="none" />
</natural-id>
--
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
14 years, 10 months
[Hibernate-JIRA] Updated: (HHH-1574) AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids (Alex Burgel)
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574?page=c... ]
Gail Badner updated HHH-1574:
-----------------------------
Assignee: Gail Badner
Fix Version/s: 3.6
3.5.2
Summary: AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids (Alex Burgel) (was: AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids)
> AbstractEntityPersister.getNaturalIdentifierSnapshot doesn't work with many-to-one ids (Alex Burgel)
> ----------------------------------------------------------------------------------------------------
>
> Key: HHH-1574
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1574
> Project: Hibernate Core
> Issue Type: Patch
> Affects Versions: 3.1.2
> Reporter: Alex Burgel
> Assignee: Gail Badner
> Fix For: 3.5.2, 3.6
>
> Attachments: resolveentity.patch, resolveentity32.patch, testcase.zip
>
>
> i just upgraded from 3.0.5 to 3.1.2, and i started seeing this problem. i'm not exactly sure where the bug is here, but this is what i'm seeing:
> i have a class, Subscription, which has a natural-id of class Subscriber and Edition (excerpts of relevant mapping files below).
> when Subscription is unloaded, if i make a change, then commit the session, i see this exception:
> HibernateException: immutable natural identifier of an instance of Subscription was altered
> this gets thrown from DefaultFlushEntityEventListener.checkNaturalId() line 80.
> i traced through that method, this is what happens:
> 1. in checkNaturalId, loaded == null , so getNaturalIdSnapshot() is called
> 2. this ends up generating some sql that selects the SubscriptionId and EditionId from the Subscription row.
> 3. the sql is generated in AbstractEntityPersister.getNaturalIdentifierSnapshot(), which calls hydrate for each returned column of the natural-id,
> 4. but hydrate only returns the id, instead of the actual entity
> 5. so this array of ids (instead of entities) ends up back in DefaultFlushEntityEventListener.checkNaturalId() as 'loaded', which gets compared to 'current'
> the trouble is that 'current' contains the entities, but 'loaded' only contains the ids of those entites, so the natural-id check fails, and i get the exception.
> this only happens when 'loaded' is null in checkNaturalId().
> the javadocs for hydrate say you have to call "resolve" afterwards... this isn't being done, so maybe thats the fix. if the natural-id is not just simple properties, then resolve should also be called.
> <class name="Subscription" table="Subscriptions" batch-size="10">
> <id name="id" column="Id" type="int"><generator class="native" /></id>
> <natural-id>
> <many-to-one name="subscriber" class="Subscriber" column="SubscriberId" />
> <many-to-one name="edition" class="Edition" column="EditionId" />
> </natural-id>
> ....
> </class>
> <class name="Subscriber" table="Subscriber">
> <id name="id" column="id" type="int"><generator class="native" /></id>
> <map name="subscriptions" inverse="true" cascade="all,delete-orphan" batch-size="10">
> <key column="SubscriberId" />
> <map-key-many-to-many column="EditionId" class="Edition" />
> <one-to-many class="Subscription" />
> </map>
> </class>
--
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
14 years, 10 months
[Hibernate-JIRA] Created: (HHH-5215) SQLQueryImpl Memory Leak causes OutOfMemoryException
by Pamir Erdem (JIRA)
SQLQueryImpl Memory Leak causes OutOfMemoryException
----------------------------------------------------
Key: HHH-5215
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5215
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.3.2
Environment: Sun Solaris 10 Sparc
Reporter: Pamir Erdem
Attachments: nativequeryspec.jpg, Query.jpg, sameQueryOutGoingRef.jpg
In one of our batch operations gets OutOfMemoryExcetion. Working on heap dump, it is found out that, same query cached more than once.
In the picture below the query is shown.
!Query.jpg!
After we found out that the root cause of the problem is the QueryPlanCache, the batch was executed under eclipse environment to find what was wrong.
Altough the only qery is the query.jpg the query plan cache was so high that it can be seen easly from MAT.
!nativequeryspec.jpg!
We get the picture below by going outgoing references from MAT.
!sameQueryOutGoingRef.jpg!
>From debugging view of eclipse, we want to produce the problem step by step to prove the heap dump.
The first step was looking at the source code where hashCode was calculated.
!!
--
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
14 years, 10 months