Issue Type: Bug Bug
Affects Versions: 4.1.7
Assignee: Unassigned
Components: entity-manager
Created: 15/Nov/12 4:55 AM
Description:

Assume the following:

Two entity types:

RelationOne
@ManyToOne
@NotFound(IGNORE)
RelationTwo relationTwo;

RelationTwo
(nothing special)

Further:
insert one instance of RelationTwo
insert two instances of RelationOne, which reference RelationTwo

Next step:
commit

Next:
new Session & TX
Load RelationOne (Session.get())
Delete RelationOne (Session.delete())
commit

Next:
new Session & TX
Load one instance of RelationTwo (everything is fine)
Load next instance of RelationTwo (FAILURE)

org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.hrs.frw.jpa.flux.test.entities.RelationTwo#RelationId{idNumber=31, idString='x1'}]
	at org.hibernate.internal.SessionFactoryImpl$1$1.handleEntityNotFound(SessionFactoryImpl.java:242)
	at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:210)
	at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
	at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
	at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1075)
	at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:1002)
	at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:613)
	at org.hibernate.type.EntityType.resolve(EntityType.java:441)
	at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
	at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:134)
	at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:999)
	at org.hibernate.loader.Loader.doQuery(Loader.java:878)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:263)
	at org.hibernate.loader.Loader.loadEntity(Loader.java:1977)

org.hibernate.event.internal.DefaultLoadEventListener#proxyOrLoad contains the following code:

		// look for a proxy
        Object proxy = persistenceContext.getProxy(keyToLoad);
        if (proxy != null) {
			return returnNarrowedProxy(event, persister, keyToLoad, options, persistenceContext, proxy);
		}

        if (options.isAllowProxyCreation()) {
			return createProxyIfNecessary(event, persister, keyToLoad, options, persistenceContext);
		}

        // return a newly loaded object
        return load(event, persister, keyToLoad, options);

The load of the first instance of RelationTwo has a null proxy variable for RelationOne, but the second load of RelationTwo has a non-null proxy variable for RelationOne. This results in a call to org.hibernate.event.internal.DefaultLoadEventListener#load which unconditionally raises an ObjectNotFound exception.

Project: Hibernate ORM
Priority: Major Major
Reporter: Robert Stupp
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira