HHH-7459 lazyness is not processed correctly
This commit is contained in:
parent
5cd3f85ac5
commit
845c757e07
|
@ -41,7 +41,7 @@ public @interface Tuplizer {
|
|||
/** tuplizer implementation */
|
||||
Class impl();
|
||||
/**
|
||||
* either pojo, dynamic-map or dom4j
|
||||
* either pojo, dynamic-map
|
||||
* @deprecated should use #entityModeType instead
|
||||
*/
|
||||
@Deprecated
|
||||
|
|
|
@ -325,7 +325,7 @@ public class DefaultLoadEventListener extends AbstractLockUpgradeEventListener i
|
|||
}
|
||||
return existing;
|
||||
}
|
||||
LOG.trace( "Creating new proxy for entity" );
|
||||
LOG.trace( "Creating new proxy for entity: " + event.getEntityClassName() );
|
||||
// return new uninitialized proxy
|
||||
Object proxy = persister.createProxy( event.getEntityId(), event.getSession() );
|
||||
persistenceContext.getBatchFetchQueue().addBatchLoadableEntityKey( keyToLoad );
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.Collections;
|
|||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.engine.spi.CascadeStyle;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.PluralAssociationAttribute;
|
||||
import org.hibernate.metamodel.internal.source.annotations.util.EnumConversionHelper;
|
||||
import org.hibernate.metamodel.spi.source.OneToManyPluralAttributeElementSource;
|
||||
|
||||
/**
|
||||
|
@ -52,8 +53,7 @@ public class OneToManyPluralAttributeElementSourceImpl implements OneToManyPlura
|
|||
|
||||
@Override
|
||||
public Iterable<CascadeStyle> getCascadeStyles() {
|
||||
// TODO
|
||||
return Collections.emptyList();
|
||||
return EnumConversionHelper.cascadeTypeToCascadeStyleSet( associationAttribute.getCascadeTypes(), associationAttribute.getContext() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -73,6 +73,11 @@ public class PluralAttributeSourceImpl implements PluralAttributeSource, Orderab
|
|||
return elementSource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMappedBy() {
|
||||
return associationAttribute.getMappedBy();
|
||||
}
|
||||
|
||||
private PluralAttributeElementSource determineElementSource() {
|
||||
switch ( associationAttribute.getNature() ) {
|
||||
case MANY_TO_MANY:
|
||||
|
|
|
@ -161,6 +161,11 @@ public class ToOneAttributeSourceImpl extends SingularAttributeSourceImpl implem
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnWrapProxy() {
|
||||
return associationAttribute.isUnWrapProxy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
|
|
@ -37,6 +37,8 @@ import org.jboss.jandex.AnnotationValue;
|
|||
import org.jboss.jandex.DotName;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.LazyToOneOption;
|
||||
import org.hibernate.annotations.NotFoundAction;
|
||||
import org.hibernate.engine.FetchStyle;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
|
@ -69,6 +71,7 @@ public class AssociationAttribute extends MappedAttribute {
|
|||
private final Set<CascadeType> cascadeTypes;
|
||||
private final boolean isOptional;
|
||||
private final boolean isLazy;
|
||||
private final boolean isUnWrapProxy;
|
||||
private final boolean isOrphanRemoval;
|
||||
private final FetchStyle fetchStyle;
|
||||
private final boolean mapsId;
|
||||
|
@ -116,6 +119,7 @@ public class AssociationAttribute extends MappedAttribute {
|
|||
this.mappedBy = determineMappedByAttributeName( associationAnnotation );
|
||||
this.isOptional = determineOptionality( associationAnnotation );
|
||||
this.isLazy = determineIsLazy( associationAnnotation );
|
||||
this.isUnWrapProxy = determinIsUnwrapProxy();
|
||||
this.isOrphanRemoval = determineOrphanRemoval( associationAnnotation );
|
||||
this.cascadeTypes = determineCascadeTypes( associationAnnotation );
|
||||
this.joinColumnValues = determineJoinColumnAnnotations( annotations );
|
||||
|
@ -180,6 +184,10 @@ public class AssociationAttribute extends MappedAttribute {
|
|||
return isLazy;
|
||||
}
|
||||
|
||||
public boolean isUnWrapProxy() {
|
||||
return isUnWrapProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptional() {
|
||||
return isOptional;
|
||||
|
@ -238,6 +246,14 @@ public class AssociationAttribute extends MappedAttribute {
|
|||
return NotFoundAction.IGNORE.equals( action );
|
||||
}
|
||||
|
||||
private boolean determinIsUnwrapProxy() {
|
||||
AnnotationInstance lazyToOne = JandexHelper.getSingleAnnotation( annotations(), HibernateDotNames.LAZY_TO_ONE );
|
||||
if ( lazyToOne != null ) {
|
||||
return JandexHelper.getEnumValue( lazyToOne, "value", LazyToOneOption.class ) == LazyToOneOption.NO_PROXY;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean determineOptionality(AnnotationInstance associationAnnotation) {
|
||||
boolean optional = true;
|
||||
|
||||
|
@ -260,7 +276,30 @@ public class AssociationAttribute extends MappedAttribute {
|
|||
|
||||
protected boolean determineIsLazy(AnnotationInstance associationAnnotation) {
|
||||
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class );
|
||||
return FetchType.LAZY == fetchType;
|
||||
boolean lazy = fetchType == FetchType.LAZY;
|
||||
final AnnotationInstance lazyToOneAnnotation = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
HibernateDotNames.LAZY_TO_ONE
|
||||
);
|
||||
if ( lazyToOneAnnotation != null ) {
|
||||
LazyToOneOption option = JandexHelper.getEnumValue( lazyToOneAnnotation, "value", LazyToOneOption.class );
|
||||
lazy = option != LazyToOneOption.FALSE;
|
||||
}
|
||||
|
||||
if ( associationAnnotation.value( "fetch" ) != null ) {
|
||||
lazy = FetchType.LAZY == fetchType;
|
||||
}
|
||||
final AnnotationInstance fetchAnnotation = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
HibernateDotNames.FETCH
|
||||
);
|
||||
if ( fetchAnnotation != null ) {
|
||||
lazy = JandexHelper.getEnumValue( fetchAnnotation, "value", FetchMode.class ) != FetchMode.JOIN;
|
||||
}
|
||||
if ( getFetchStyle() != null ) {
|
||||
lazy = getFetchStyle() != FetchStyle.JOIN;
|
||||
}
|
||||
return lazy;
|
||||
}
|
||||
|
||||
private String determineReferencedEntityType(AnnotationInstance associationAnnotation, Class<?> referencedAttributeType) {
|
||||
|
|
|
@ -26,12 +26,15 @@ package org.hibernate.metamodel.internal.source.annotations.attribute;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.FetchType;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
import org.hibernate.annotations.FetchMode;
|
||||
import org.hibernate.annotations.LazyCollectionOption;
|
||||
import org.hibernate.annotations.OnDeleteAction;
|
||||
import org.hibernate.annotations.SortType;
|
||||
|
@ -230,8 +233,11 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
|
||||
AnnotationInstance orderColumnAnnotation = JandexHelper.getSingleAnnotation( annotations, JPADotNames.ORDER_COLUMN );
|
||||
AnnotationInstance indexColumnAnnotation = JandexHelper.getSingleAnnotation( annotations, HibernateDotNames.INDEX_COLUMN );
|
||||
if(orderColumnAnnotation!=null && indexColumnAnnotation!=null){
|
||||
throw new MappingException( "@OrderColumn and @IndexColumn can't be used together on property: " + getRole() ,getContext().getOrigin() );
|
||||
if ( orderColumnAnnotation != null && indexColumnAnnotation != null ) {
|
||||
throw new MappingException(
|
||||
"@OrderColumn and @IndexColumn can't be used together on property: " + getRole(),
|
||||
getContext().getOrigin()
|
||||
);
|
||||
}
|
||||
this.isIndexed = orderColumnAnnotation != null || indexColumnAnnotation != null;
|
||||
|
||||
|
@ -276,9 +282,11 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
}
|
||||
return entityPersisterClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean determineIsLazy(AnnotationInstance associationAnnotation) {
|
||||
boolean lazy = super.determineIsLazy( associationAnnotation );
|
||||
FetchType fetchType = JandexHelper.getEnumValue( associationAnnotation, "fetch", FetchType.class );
|
||||
boolean lazy = fetchType == FetchType.LAZY;
|
||||
final AnnotationInstance lazyCollectionAnnotationInstance = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
HibernateDotNames.LAZY_COLLECTION
|
||||
|
@ -289,9 +297,19 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
|||
"value",
|
||||
LazyCollectionOption.class
|
||||
);
|
||||
return lazyOption == LazyCollectionOption.TRUE;
|
||||
lazy = !( lazyOption == LazyCollectionOption.FALSE );
|
||||
|
||||
}
|
||||
final AnnotationInstance fetchAnnotation = JandexHelper.getSingleAnnotation(
|
||||
annotations(),
|
||||
HibernateDotNames.FETCH
|
||||
);
|
||||
if ( fetchAnnotation != null && fetchAnnotation.value() != null ) {
|
||||
FetchMode fetchMode = FetchMode.valueOf( fetchAnnotation.value( ).asEnum().toUpperCase() );
|
||||
if ( fetchMode == FetchMode.JOIN ) {
|
||||
lazy = false;
|
||||
}
|
||||
}
|
||||
return lazy;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.hibernate.AssertionFailure;
|
|||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.metamodel.internal.source.annotations.AnnotationBindingContext;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AssociationAttribute;
|
||||
import org.hibernate.metamodel.internal.source.annotations.attribute.AttributeOverride;
|
||||
|
@ -526,10 +527,10 @@ public class ConfiguredClass {
|
|||
if ( embeddableClassInfo == null ) {
|
||||
final String msg = String.format(
|
||||
"Attribute '%s#%s' is annotated with @Embedded, but '%s' does not seem to be annotated " +
|
||||
"with @Embeddable. Are all annotated classes added to the configuration?",
|
||||
getConfiguredClass().getSimpleName(),
|
||||
"with @Embeddable.\n Are all annotated classes added to the configuration?",
|
||||
getConfiguredClass().getName(),
|
||||
attributeName,
|
||||
type.getSimpleName()
|
||||
type.getName()
|
||||
);
|
||||
throw new AnnotationException( msg );
|
||||
}
|
||||
|
@ -669,6 +670,9 @@ public class ConfiguredClass {
|
|||
}
|
||||
|
||||
private Class<?> resolveCollectionValuedReferenceType(ResolvedMember resolvedMember) {
|
||||
if ( resolvedMember.getType().isArray() ) {
|
||||
return resolvedMember.getType().getArrayElementType().getErasedType();
|
||||
}
|
||||
if ( resolvedMember.getType().getTypeParameters().isEmpty() ) {
|
||||
return null; // no generic at all
|
||||
}
|
||||
|
@ -752,28 +756,44 @@ public class ConfiguredClass {
|
|||
final AnnotationInstance tuplizersAnnotation = JandexHelper.getSingleAnnotation(
|
||||
classInfo, HibernateDotNames.TUPLIZERS
|
||||
);
|
||||
if ( tuplizersAnnotation == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
AnnotationInstance[] annotations = JandexHelper.getValue(
|
||||
tuplizersAnnotation,
|
||||
"value",
|
||||
AnnotationInstance[].class
|
||||
final AnnotationInstance tuplizerAnnotation = JandexHelper.getSingleAnnotation(
|
||||
classInfo,
|
||||
HibernateDotNames.TUPLIZER
|
||||
);
|
||||
|
||||
AnnotationInstance pojoTuplizerAnnotation = null;
|
||||
for ( AnnotationInstance tuplizerAnnotation : annotations ) {
|
||||
if ( EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() ) == EntityMode.POJO ) {
|
||||
pojoTuplizerAnnotation = tuplizerAnnotation;
|
||||
break;
|
||||
if ( tuplizersAnnotation != null ) {
|
||||
AnnotationInstance[] annotations = JandexHelper.getValue(
|
||||
tuplizersAnnotation,
|
||||
"value",
|
||||
AnnotationInstance[].class
|
||||
);
|
||||
for ( final AnnotationInstance annotationInstance : annotations ) {
|
||||
final String impl = findTuplizerImpl( annotationInstance );
|
||||
if ( StringHelper.isNotEmpty( impl ) ) {
|
||||
return impl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String customTuplizer = null;
|
||||
if ( pojoTuplizerAnnotation != null ) {
|
||||
customTuplizer = pojoTuplizerAnnotation.value( "impl" ).asString();
|
||||
else if ( tuplizerAnnotation != null ) {
|
||||
final String impl = findTuplizerImpl( tuplizerAnnotation );
|
||||
if ( StringHelper.isNotEmpty( impl ) ) {
|
||||
return impl;
|
||||
}
|
||||
}
|
||||
return customTuplizer;
|
||||
return null;
|
||||
}
|
||||
|
||||
private String findTuplizerImpl(final AnnotationInstance tuplizerAnnotation) {
|
||||
EntityMode mode;
|
||||
if ( tuplizerAnnotation.value( "entityModeType" ) != null ) {
|
||||
mode = EntityMode.valueOf( tuplizerAnnotation.value( "entityModeType" ).asEnum() );
|
||||
}
|
||||
else if ( tuplizerAnnotation.value( "entityMode" ) != null ) {
|
||||
mode = EntityMode.parse( tuplizerAnnotation.value( "entityMode" ).asString() );
|
||||
}
|
||||
else {
|
||||
mode = EntityMode.POJO;
|
||||
}
|
||||
return mode == EntityMode.POJO ? tuplizerAnnotation.value( "impl" ).asString() : null;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ public class EntityClass extends ConfiguredClass {
|
|||
private final List<String> synchronizedTableNames;
|
||||
private final int batchSize;
|
||||
|
||||
private boolean isMutable;
|
||||
private boolean isImmutable;
|
||||
private boolean isExplicitPolymorphism;
|
||||
private OptimisticLockStyle optimisticLockStyle;
|
||||
private String whereClause;
|
||||
|
@ -152,7 +152,7 @@ public class EntityClass extends ConfiguredClass {
|
|||
}
|
||||
|
||||
public boolean isMutable() {
|
||||
return isMutable;
|
||||
return !isImmutable;
|
||||
}
|
||||
|
||||
public OptimisticLockStyle getOptimisticLockStyle() {
|
||||
|
@ -287,11 +287,16 @@ public class EntityClass extends ConfiguredClass {
|
|||
optimisticLockStyle = OptimisticLockStyle.valueOf( optimisticLockType.name() );
|
||||
|
||||
AnnotationInstance hibernateImmutableAnnotation = JandexHelper.getSingleAnnotation( getClassInfo(), HibernateDotNames.IMMUTABLE, ClassInfo.class );
|
||||
isMutable = hibernateImmutableAnnotation == null
|
||||
&& hibernateEntityAnnotation != null
|
||||
&& hibernateEntityAnnotation.value( "mutable" ) != null
|
||||
&& hibernateEntityAnnotation.value( "mutable" ).asBoolean();
|
||||
if ( hibernateImmutableAnnotation != null ) {
|
||||
isImmutable = true;
|
||||
}
|
||||
else if (hibernateEntityAnnotation != null
|
||||
&& hibernateEntityAnnotation.value( "mutable" ) != null){
|
||||
|
||||
isImmutable = !hibernateEntityAnnotation.value( "mutable" ).asBoolean();
|
||||
} else {
|
||||
isImmutable = false;
|
||||
}
|
||||
|
||||
final AnnotationInstance whereAnnotation = JandexHelper.getSingleAnnotation(
|
||||
getClassInfo(), HibernateDotNames.WHERE
|
||||
|
|
|
@ -127,6 +127,14 @@ class ManyToOneAttributeSourceImpl extends AbstractHbmSourceNode implements ToOn
|
|||
return getFetchTiming() != FetchTiming.IMMEDIATE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUnWrapProxy() {
|
||||
final String lazySelection = manyToOneElement.getLazy() != null
|
||||
? manyToOneElement.getLazy().value()
|
||||
: null;
|
||||
return lazySelection != null && lazySelection.equals( "no-proxy" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public SingularAttributeBinding.NaturalIdMutability getNaturalIdMutability() {
|
||||
return naturalIdMutability;
|
||||
|
|
|
@ -53,7 +53,7 @@ public class ManyToOneAttributeBinding
|
|||
private CascadeStyle cascadeStyle;
|
||||
private FetchTiming fetchTiming;
|
||||
private FetchStyle fetchStyle;
|
||||
|
||||
private boolean isUnWrapProxy;
|
||||
public ManyToOneAttributeBinding(
|
||||
AttributeBindingContainer container,
|
||||
SingularAttribute attribute,
|
||||
|
@ -180,6 +180,14 @@ public class ManyToOneAttributeBinding
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isUnWrapProxy() {
|
||||
return isUnWrapProxy;
|
||||
}
|
||||
|
||||
public void setUnWrapProxy(boolean unWrapProxy) {
|
||||
isUnWrapProxy = unWrapProxy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final EntityBinding getReferencedEntityBinding() {
|
||||
return referencedEntityBinding;
|
||||
|
|
|
@ -41,4 +41,6 @@ public interface SingularAssociationAttributeBinding extends SingularAttributeBi
|
|||
public EntityBinding getReferencedEntityBinding();
|
||||
|
||||
public SingularAttributeBinding getReferencedAttributeBinding();
|
||||
public boolean isUnWrapProxy();
|
||||
public void setUnWrapProxy(boolean unWrapProxy);
|
||||
}
|
|
@ -43,6 +43,6 @@ public interface ToOneAttributeSource
|
|||
* @return The name of the referenced entity
|
||||
*/
|
||||
public String getReferencedEntityName();
|
||||
|
||||
public boolean isUnWrapProxy();
|
||||
public List<Binder.DefaultNamingStrategy> getDefaultNamingStrategies(final String entityName, final String tableName, final AttributeBinding referencedAttributeBinding);
|
||||
}
|
||||
|
|
|
@ -250,16 +250,25 @@ public class EnumType implements EnhancedUserType, DynamicParameterizedType, Ser
|
|||
|
||||
@Override
|
||||
public String objectToSQLString(Object value) {
|
||||
if(enumValueMapper==null){
|
||||
guessTypeOfEnumValueMapper( sqlType );
|
||||
}
|
||||
return enumValueMapper.objectToSQLString( (Enum) value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toXMLString(Object value) {
|
||||
if(enumValueMapper==null){
|
||||
guessTypeOfEnumValueMapper( sqlType );
|
||||
}
|
||||
return enumValueMapper.toXMLString( (Enum) value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object fromXMLString(String xmlValue) {
|
||||
if(enumValueMapper==null){
|
||||
guessTypeOfEnumValueMapper( sqlType );
|
||||
}
|
||||
return enumValueMapper.fromXMLString( xmlValue );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue