HHH-11576 : Correct AbstractEntityTuplizer#getPropertyValues to work with new Enhancer
This commit is contained in:
parent
aca472bb65
commit
4346c25531
|
@ -7,7 +7,7 @@
|
|||
package org.hibernate.event.internal;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.internal.Collections;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
|
|
|
@ -14,12 +14,15 @@ import java.util.Set;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.LazyAttributeLoader;
|
||||
import org.hibernate.bytecode.instrumentation.internal.FieldInterceptionHelper;
|
||||
import org.hibernate.bytecode.instrumentation.spi.FieldInterceptor;
|
||||
import org.hibernate.bytecode.instrumentation.spi.LazyPropertyInitializer;
|
||||
import org.hibernate.bytecode.spi.EntityInstrumentationMetadata;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptable;
|
||||
import org.hibernate.engine.spi.PersistentAttributeInterceptor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.event.service.spi.EventListenerRegistry;
|
||||
|
@ -495,19 +498,32 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
|
|||
public Object[] getPropertyValues(Object entity) throws HibernateException {
|
||||
final int span = entityMetamodel.getPropertySpan();
|
||||
final Object[] result = new Object[span];
|
||||
final EntityInstrumentationMetadata enhancementMetadata = entityMetamodel.getInstrumentationMetadata();
|
||||
final FieldInterceptor interceptor = enhancementMetadata.isInstrumented()
|
||||
? enhancementMetadata.extractInterceptor( entity )
|
||||
: null;
|
||||
|
||||
LazyAttributeLoader lazyAttributeLoader = null;
|
||||
FieldInterceptor fieldInterceptor = null;
|
||||
if ( entity instanceof PersistentAttributeInterceptable ) {
|
||||
PersistentAttributeInterceptor interceptor = ( (PersistentAttributeInterceptable) entity ).$$_hibernate_getInterceptor();
|
||||
if ( interceptor != null && interceptor instanceof LazyAttributeLoader ) {
|
||||
lazyAttributeLoader = (LazyAttributeLoader) interceptor;
|
||||
}
|
||||
}
|
||||
// Don't bother checking for FieldInterceptor if lazyAttributeLoader is non-null.
|
||||
if ( lazyAttributeLoader == null && FieldInterceptionHelper.isInstrumented( entity ) ) {
|
||||
fieldInterceptor = FieldInterceptionHelper.extractFieldInterceptor( entity );
|
||||
}
|
||||
|
||||
for ( int j = 0; j < span; j++ ) {
|
||||
NonIdentifierAttribute property = entityMetamodel.getProperties()[j];
|
||||
if ( !property.isLazy() || interceptor == null || interceptor.isInitialized( property.getName() ) ) {
|
||||
result[j] = getters[j].get( entity );
|
||||
}
|
||||
else {
|
||||
result[j] = LazyPropertyInitializer.UNFETCHED_PROPERTY;
|
||||
boolean isInitialized = true;
|
||||
if ( property.isLazy() ) {
|
||||
if ( lazyAttributeLoader != null ) {
|
||||
isInitialized = lazyAttributeLoader.isAttributeLoaded( property.getName() );
|
||||
}
|
||||
else if ( fieldInterceptor != null ) {
|
||||
isInitialized = fieldInterceptor.isInitialized( property.getName() );
|
||||
}
|
||||
}
|
||||
result[j] = isInitialized ? getters[j].get( entity ) : LazyPropertyInitializer.UNFETCHED_PROPERTY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@Entity( name = "AdditionalDetails" )
|
||||
public class AdditionalDetails {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
String details;
|
||||
|
||||
@OneToOne( optional = false )
|
||||
@MapsId
|
||||
Post post;
|
||||
}
|
|
@ -12,14 +12,6 @@ import org.hibernate.cfg.Configuration;
|
|||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -29,7 +21,6 @@ import static org.junit.Assert.assertFalse;
|
|||
* @author Luis Barreiro
|
||||
*/
|
||||
public class LazyCollectionDeletedTestTask extends AbstractEnhancerTestTask {
|
||||
private static final int CHILDREN_SIZE = 10;
|
||||
private Long postId;
|
||||
|
||||
public Class<?>[] getAnnotatedClasses() {
|
||||
|
@ -95,43 +86,4 @@ public class LazyCollectionDeletedTestTask extends AbstractEnhancerTestTask {
|
|||
|
||||
protected void cleanup() {
|
||||
}
|
||||
|
||||
// --- //
|
||||
|
||||
@Entity( name = "Tag" )
|
||||
public static class Tag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
}
|
||||
|
||||
@Entity( name = "Post" )
|
||||
public static class Post {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToMany( cascade = CascadeType.ALL )
|
||||
private Set<Tag> tags;
|
||||
|
||||
@OneToOne( fetch = FetchType.LAZY, mappedBy = "post", cascade = CascadeType.ALL )
|
||||
private AdditionalDetails additionalDetails;
|
||||
}
|
||||
|
||||
@Entity( name = "AdditionalDetails" )
|
||||
public static class AdditionalDetails {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String details;
|
||||
|
||||
@OneToOne( optional = false )
|
||||
@MapsId
|
||||
private Post post;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Set;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@Entity( name = "Post" )
|
||||
public class Post {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
@ManyToMany( cascade = CascadeType.ALL )
|
||||
Set<Tag> tags;
|
||||
|
||||
@OneToOne( fetch = FetchType.LAZY, mappedBy = "post", cascade = CascadeType.ALL )
|
||||
AdditionalDetails additionalDetails;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* @author Luis Barreiro
|
||||
*/
|
||||
@Entity( name = "Tag" )
|
||||
public class Tag {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Long id;
|
||||
|
||||
String name;
|
||||
}
|
||||
|
Loading…
Reference in New Issue