HHH-8359 default-lazy from <hibernate-mapping> should be applied to all entities / attributes if no one provided from the sub element
This commit is contained in:
parent
2bc611a20c
commit
d8c13ca9aa
|
@ -33,7 +33,7 @@ public interface EntityElement extends MetaAttributeContainer {
|
||||||
public String getEntityName();
|
public String getEntityName();
|
||||||
|
|
||||||
public boolean isAbstract();
|
public boolean isAbstract();
|
||||||
public boolean isLazy();
|
public Boolean isLazy();
|
||||||
public String getProxy();
|
public String getProxy();
|
||||||
public int getBatchSize();
|
public int getBatchSize();
|
||||||
public boolean isDynamicInsert();
|
public boolean isDynamicInsert();
|
||||||
|
|
|
@ -52,6 +52,9 @@ import org.hibernate.metamodel.internal.source.annotations.RootEntitySourceImpl;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.SubclassEntitySourceImpl;
|
import org.hibernate.metamodel.internal.source.annotations.SubclassEntitySourceImpl;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.EntityClass;
|
||||||
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
import org.hibernate.metamodel.internal.source.annotations.entity.RootEntityClass;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.n.ClassNode;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.n.HierarchyBuilder;
|
||||||
|
import org.hibernate.metamodel.internal.source.annotations.n.TreeWalker;
|
||||||
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
import org.hibernate.metamodel.spi.binding.InheritanceType;
|
||||||
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
import org.hibernate.metamodel.spi.source.EntityHierarchy;
|
||||||
import org.hibernate.metamodel.spi.source.EntitySource;
|
import org.hibernate.metamodel.spi.source.EntitySource;
|
||||||
|
@ -78,6 +81,11 @@ public class EntityHierarchyBuilder {
|
||||||
* @return a set of {@code EntityHierarchy} instances.
|
* @return a set of {@code EntityHierarchy} instances.
|
||||||
*/
|
*/
|
||||||
public static Set<EntityHierarchy> createEntityHierarchies(AnnotationBindingContext bindingContext) {
|
public static Set<EntityHierarchy> createEntityHierarchies(AnnotationBindingContext bindingContext) {
|
||||||
|
|
||||||
|
HierarchyBuilder builder = new HierarchyBuilder( bindingContext );
|
||||||
|
ClassNode root = builder.create();
|
||||||
|
new TreeWalker().visit( root );
|
||||||
|
|
||||||
Set<EntityHierarchy> hierarchies = new HashSet<EntityHierarchy>();
|
Set<EntityHierarchy> hierarchies = new HashSet<EntityHierarchy>();
|
||||||
Map<DotName,DotName> processedEntities = new HashMap<DotName, DotName>( );
|
Map<DotName,DotName> processedEntities = new HashMap<DotName, DotName>( );
|
||||||
Map<DotName, List<ClassInfo>> classToDirectSubClassMap = new HashMap<DotName, List<ClassInfo>>();
|
Map<DotName, List<ClassInfo>> classToDirectSubClassMap = new HashMap<DotName, List<ClassInfo>>();
|
||||||
|
|
|
@ -447,6 +447,9 @@ public abstract class AbstractEntitySourceImpl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isLazy() {
|
public boolean isLazy() {
|
||||||
|
if(entityElement.isLazy()==null){
|
||||||
|
return getLocalBindingContext().getMappingDefaults().areAssociationsLazy();
|
||||||
|
}
|
||||||
return entityElement().isLazy();
|
return entityElement().isLazy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1576,7 +1576,7 @@ arbitrary number of queries, and import declarations of arbitrary classes.
|
||||||
<xs:attribute name="dynamic-update" default="false" type="xs:boolean"/>
|
<xs:attribute name="dynamic-update" default="false" type="xs:boolean"/>
|
||||||
<xs:attribute name="entity-name" type="xs:string"/>
|
<xs:attribute name="entity-name" type="xs:string"/>
|
||||||
<!-- default: none when toplevel, otherwise the nearest class definition -->
|
<!-- default: none when toplevel, otherwise the nearest class definition -->
|
||||||
<xs:attribute name="lazy" default="true" type="xs:boolean"/>
|
<xs:attribute name="lazy" type="xs:boolean"/>
|
||||||
<xs:attribute name="name" type="xs:string"/>
|
<xs:attribute name="name" type="xs:string"/>
|
||||||
<xs:attribute name="node" type="xs:string"/>
|
<xs:attribute name="node" type="xs:string"/>
|
||||||
<xs:attribute name="persister" type="xs:string"/>
|
<xs:attribute name="persister" type="xs:string"/>
|
||||||
|
|
|
@ -26,6 +26,7 @@ package org.hibernate.test.annotations.embeddables.nested;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
import javax.persistence.Embeddable;
|
import javax.persistence.Embeddable;
|
||||||
|
import javax.persistence.Embedded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Thomas Vanstals
|
* @author Thomas Vanstals
|
||||||
|
@ -36,7 +37,7 @@ public class Investment {
|
||||||
private MonetaryAmount amount;
|
private MonetaryAmount amount;
|
||||||
private String description;
|
private String description;
|
||||||
private Date date;
|
private Date date;
|
||||||
|
@Embedded
|
||||||
public MonetaryAmount getAmount() {
|
public MonetaryAmount getAmount() {
|
||||||
return amount;
|
return amount;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,14 @@ import org.hibernate.mapping.Component;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
import org.hibernate.mapping.PersistentClass;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
|
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.CompositePluralAttributeElementBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.PluralAttributeElementBinding;
|
||||||
|
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
|
||||||
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||||
import org.hibernate.type.CustomType;
|
import org.hibernate.type.CustomType;
|
||||||
|
|
||||||
|
@ -43,21 +51,56 @@ import static org.junit.Assert.assertEquals;
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
public class NestedEmbeddableMetadataTest extends BaseUnitTestCase {
|
public class NestedEmbeddableMetadataTest extends BaseCoreFunctionalTestCase {
|
||||||
|
@Override
|
||||||
|
protected Class<?>[] getAnnotatedClasses() {
|
||||||
|
return new Class[] { Customer.class, Investment.class, MonetaryAmount.class };
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEnumTypeInterpretation() {
|
public void testEnumTypeInterpretation() {
|
||||||
Configuration cfg = new Configuration().addAnnotatedClass( Customer.class );
|
|
||||||
cfg.buildMappings();
|
CustomType currencyType = getCurrencyAttributeType();
|
||||||
Mapping mapping = cfg.buildMapping();
|
int[] currencySqlTypes = currencyType.sqlTypes( sessionFactory() );
|
||||||
PersistentClass classMetadata = cfg.getClassMapping( Customer.class.getName() );
|
assertEquals( 1, currencySqlTypes.length );
|
||||||
|
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomType getCurrencyAttributeType() {
|
||||||
|
if ( isMetadataUsed() ) {
|
||||||
|
return getCustomTypeFromMetamodel();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getCustomTypeFromConfiguration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomType getCustomTypeFromMetamodel() {
|
||||||
|
EntityBinding entityBinding = getEntityBinding( Customer.class );
|
||||||
|
PluralAttributeBinding attributeBinding = (PluralAttributeBinding) entityBinding.locateAttributeBinding(
|
||||||
|
"investments"
|
||||||
|
);
|
||||||
|
CompositePluralAttributeElementBinding pluralAttributeElementBinding = (CompositePluralAttributeElementBinding) attributeBinding
|
||||||
|
.getPluralAttributeElementBinding();
|
||||||
|
|
||||||
|
CompositeAttributeBinding compositeAttributeBinding = (CompositeAttributeBinding) pluralAttributeElementBinding
|
||||||
|
.getCompositeAttributeBindingContainer()
|
||||||
|
.locateAttributeBinding( "amount" );
|
||||||
|
|
||||||
|
SingularAttributeBinding currencyAttributeBinding = (SingularAttributeBinding) compositeAttributeBinding.locateAttributeBinding(
|
||||||
|
"currency"
|
||||||
|
);
|
||||||
|
return (CustomType) currencyAttributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||||
|
}
|
||||||
|
|
||||||
|
private CustomType getCustomTypeFromConfiguration() {
|
||||||
|
PersistentClass classMetadata = configuration().getClassMapping( Customer.class.getName() );
|
||||||
Property investmentsProperty = classMetadata.getProperty( "investments" );
|
Property investmentsProperty = classMetadata.getProperty( "investments" );
|
||||||
Collection investmentsValue = (Collection) investmentsProperty.getValue();
|
Collection investmentsValue = (Collection) investmentsProperty.getValue();
|
||||||
Component investmentMetadata = (Component) investmentsValue.getElement();
|
Component investmentMetadata = (Component) investmentsValue.getElement();
|
||||||
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
Component amountMetadata = (Component) investmentMetadata.getProperty( "amount" ).getValue();
|
||||||
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
SimpleValue currencyMetadata = (SimpleValue) amountMetadata.getProperty( "currency" ).getValue();
|
||||||
CustomType currencyType = (CustomType) currencyMetadata.getType();
|
return (CustomType) currencyMetadata.getType();
|
||||||
int[] currencySqlTypes = currencyType.sqlTypes( mapping );
|
|
||||||
assertEquals( 1, currencySqlTypes.length );
|
|
||||||
assertJdbcTypeCode( Types.VARCHAR, currencySqlTypes[0] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.dialect.MySQLDialect;
|
import org.hibernate.dialect.MySQLDialect;
|
||||||
import org.hibernate.engine.spi.SessionImplementor;
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
import org.hibernate.jdbc.Work;
|
import org.hibernate.jdbc.Work;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
@ -241,7 +240,6 @@ public class MultiTableTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testMultiTable() throws Exception {
|
public void testMultiTable() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
@ -380,7 +378,6 @@ public class MultiTableTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testMultiTableGeneratedId() throws Exception {
|
public void testMultiTableGeneratedId() throws Exception {
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction t = s.beginTransaction();
|
Transaction t = s.beginTransaction();
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.junit.Test;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@ -47,7 +46,6 @@ public class OneToOneCacheTest extends LegacyTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@FailureExpectedWithNewMetamodel
|
|
||||||
public void testOneToOneCache() throws HibernateException {
|
public void testOneToOneCache() throws HibernateException {
|
||||||
|
|
||||||
//create a new MainObject
|
//create a new MainObject
|
||||||
|
|
Loading…
Reference in New Issue