Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-13705 Enhancement as Proxy with inline dirty checking - flush of an @ManyToOne with an Embedded value having not null properties causes PropertyValueException #3092

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hibernate.engine.spi.PersistenceContext;
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
import org.hibernate.engine.spi.SelfDirtinessTracker;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.engine.spi.Status;
import org.hibernate.mapping.PersistentClass;
Expand Down Expand Up @@ -140,8 +141,14 @@ public PersistentAttributeInterceptable createEnhancedProxy(EntityKey entityKey,
final PersistenceContext persistenceContext = session.getPersistenceContext();

// first, instantiate the entity instance to use as the proxy
final PersistentAttributeInterceptable entity = (PersistentAttributeInterceptable) persister.getEntityTuplizer().instantiate( identifier, session );
final EntityTuplizer entityTuplizer = persister.getEntityTuplizer();
final PersistentAttributeInterceptable entity = (PersistentAttributeInterceptable) entityTuplizer
.instantiate( identifier, session );

// clear the fields that are marked as dirty in the dirtyness tracker
if ( entity instanceof SelfDirtinessTracker ) {
( (SelfDirtinessTracker) entity ).$$_hibernate_clearDirtyAttributes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But didn't you just instantiate the entity?

Copy link
Member Author

@dreab8 dreab8 Nov 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what I noticed is that when

@Entity(name = "Client")
public static class Client {
        ....
	@Embedded
	private Log log = new Log();
}

is instantiated, because the field log has an assigned initial value new Log() a call of $$_hibernate_write_log and then of $$_hibernate_trackChange is triggered so the newly instantiated entity results dirty.

This happens with all the fields that have an assigned initial value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably a better approach is to add to the enhanced class the ability to reset the tracker on exit of the constructor method

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, you explained it.. that's reasonable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative (same net effect) would be to disable dirty tracking during construction

}
// add the entity (proxy) instance to the PC
persistenceContext.addEnhancedProxy( entityKey, entity );

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.test.bytecode.enhancement.lazy.proxy.inlinedirtychecking;

import org.hibernate.bytecode.enhance.spi.UnloadedClass;

import org.hibernate.testing.bytecode.enhancement.EnhancerTestContext;

/**
* @author Andrea Boriero
*/
public class DirtyCheckEnhancementContext extends EnhancerTestContext {
@Override
public boolean doExtendedEnhancement(UnloadedClass classDescriptor) {
return false;
}
}
Loading