mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-17 00:24:57 +00:00
HHH-7485 Collection Caching region is bindded with wrong default region in annotation side
This commit is contained in:
parent
127283374d
commit
b6f068a1f0
@ -27,6 +27,7 @@
|
||||
import java.util.Map;
|
||||
|
||||
import org.jboss.jandex.AnnotationInstance;
|
||||
import org.jboss.jandex.ClassInfo;
|
||||
import org.jboss.jandex.DotName;
|
||||
|
||||
import org.hibernate.AnnotationException;
|
||||
@ -53,18 +54,21 @@ public class PluralAssociationAttribute extends AssociationAttribute {
|
||||
private final CustomSQL customInsert;
|
||||
private final CustomSQL customUpdate;
|
||||
private final CustomSQL customDelete;
|
||||
private final ClassInfo entityClassInfo;
|
||||
|
||||
|
||||
// Used for the non-owning side of a ManyToMany relationship
|
||||
private final String inverseForeignKeyName;
|
||||
|
||||
public static PluralAssociationAttribute createPluralAssociationAttribute(String name,
|
||||
public static PluralAssociationAttribute createPluralAssociationAttribute(ClassInfo entityClassInfo,
|
||||
String name,
|
||||
Class<?> attributeType,
|
||||
AttributeNature attributeNature,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
return new PluralAssociationAttribute(
|
||||
entityClassInfo,
|
||||
name,
|
||||
attributeType,
|
||||
attributeNature,
|
||||
@ -106,13 +110,15 @@ public CustomSQL getCustomDelete() {
|
||||
return customDelete;
|
||||
}
|
||||
|
||||
private PluralAssociationAttribute(String name,
|
||||
private PluralAssociationAttribute(ClassInfo entityClassInfo,
|
||||
String name,
|
||||
Class<?> javaType,
|
||||
AttributeNature associationType,
|
||||
String accessType,
|
||||
Map<DotName, List<AnnotationInstance>> annotations,
|
||||
EntityBindingContext context) {
|
||||
super( name, javaType, associationType, accessType, annotations, context );
|
||||
this.entityClassInfo = entityClassInfo;
|
||||
this.whereClause = determineWereClause();
|
||||
this.orderBy = determineOrderBy();
|
||||
this.inverseForeignKeyName = determineInverseForeignKeyName();
|
||||
@ -220,7 +226,7 @@ private Caching determineCachingSettings() {
|
||||
|
||||
return new Caching(
|
||||
hibernateCacheAnnotation.value( "region" ) == null
|
||||
? getName()
|
||||
? StringHelper.qualify( entityClassInfo.name().toString(), getName() )
|
||||
: hibernateCacheAnnotation.value( "region" ).asString(),
|
||||
accessType,
|
||||
hibernateCacheAnnotation.value( "include" ) != null
|
||||
|
@ -479,6 +479,7 @@ attributeName, attributeType, attributeNature, annotations, accessTypeString, ge
|
||||
case ONE_TO_MANY:
|
||||
case MANY_TO_MANY: {
|
||||
AssociationAttribute attribute = PluralAssociationAttribute.createPluralAssociationAttribute(
|
||||
classInfo,
|
||||
attributeName,
|
||||
attributeType,
|
||||
attributeNature,
|
||||
|
@ -33,6 +33,8 @@
|
||||
import org.hibernate.NaturalIdLoadAccess;
|
||||
import org.hibernate.cache.infinispan.access.PutFromLoadValidator;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
@ -57,11 +59,6 @@
|
||||
*/
|
||||
public class BasicTransactionalTestCase extends AbstractFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
public void configure(Configuration cfg) {
|
||||
super.configure( cfg );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?>[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
@ -263,8 +260,8 @@ public void testQueryCacheInvalidation() throws Exception {
|
||||
s = openSession();
|
||||
t = s.beginTransaction();
|
||||
i = (Item) s.get( Item.class, i.getId() );
|
||||
assertEquals( slcs.getHitCount(), 1 );
|
||||
assertEquals( slcs.getMissCount(), 0 );
|
||||
assertEquals( 1, slcs.getHitCount() );
|
||||
assertEquals( 0, slcs.getMissCount() );
|
||||
i.setDescription( "A bog standard item" );
|
||||
t.commit();
|
||||
s.close();
|
||||
@ -276,12 +273,12 @@ public void testQueryCacheInvalidation() throws Exception {
|
||||
commitOrRollbackTx();
|
||||
}
|
||||
|
||||
assertEquals( slcs.getPutCount(), 2 );
|
||||
assertEquals( 2, slcs.getPutCount() );
|
||||
|
||||
CacheEntry entry = (CacheEntry) slcs.getEntries().get( i.getId() );
|
||||
Serializable[] ser = entry.getDisassembledState();
|
||||
assertTrue( ser[0].equals( "widget" ) );
|
||||
assertTrue( ser[1].equals( "A bog standard item" ) );
|
||||
Assert.assertEquals( "widget", ser[0] );
|
||||
assertEquals( "A bog standard item", ser[1] );
|
||||
|
||||
beginTx();
|
||||
try {
|
||||
|
@ -40,6 +40,7 @@
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.Interceptor;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cache.spi.access.AccessType;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
@ -47,6 +48,7 @@
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.jdbc.AbstractReturningWork;
|
||||
import org.hibernate.jdbc.Work;
|
||||
@ -55,6 +57,11 @@
|
||||
import org.hibernate.mapping.Property;
|
||||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.metamodel.MetadataSources;
|
||||
import org.hibernate.metamodel.spi.binding.AbstractPluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.AttributeBinding;
|
||||
import org.hibernate.metamodel.spi.binding.Caching;
|
||||
import org.hibernate.metamodel.spi.binding.EntityBinding;
|
||||
import org.hibernate.metamodel.spi.binding.PluralAttributeBinding;
|
||||
import org.hibernate.metamodel.spi.source.MetadataImplementor;
|
||||
import org.hibernate.service.BootstrapServiceRegistry;
|
||||
import org.hibernate.service.BootstrapServiceRegistryBuilder;
|
||||
@ -68,6 +75,7 @@
|
||||
import org.hibernate.testing.OnFailure;
|
||||
import org.hibernate.testing.SkipLog;
|
||||
import org.hibernate.testing.cache.CachingRegionFactory;
|
||||
import org.hibernate.type.Type;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@ -136,7 +144,12 @@ public Boolean convert(Object value) {
|
||||
false
|
||||
);
|
||||
if ( isMetadataUsed ) {
|
||||
sessionFactory = ( SessionFactoryImplementor ) buildMetadata( serviceRegistry ).buildSessionFactory();
|
||||
MetadataImplementor metadataImplementor = buildMetadata( serviceRegistry );
|
||||
afterConstructAndConfigureMetadata( metadataImplementor );
|
||||
applyCacheSettings(metadataImplementor);
|
||||
sessionFactory = ( SessionFactoryImplementor ) metadataImplementor.buildSessionFactory();
|
||||
|
||||
|
||||
}
|
||||
else {
|
||||
// this is done here because Configuration does not currently support 4.0 xsd
|
||||
@ -146,6 +159,10 @@ public Boolean convert(Object value) {
|
||||
afterSessionFactoryBuilt();
|
||||
}
|
||||
|
||||
protected void afterConstructAndConfigureMetadata(MetadataImplementor metadataImplementor) {
|
||||
|
||||
}
|
||||
|
||||
private MetadataImplementor buildMetadata(ServiceRegistry serviceRegistry) {
|
||||
MetadataSources sources = new MetadataSources( serviceRegistry );
|
||||
addMappings( sources );
|
||||
@ -272,6 +289,50 @@ protected String[] getXmlFiles() {
|
||||
return NO_MAPPINGS;
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(MetadataImplementor metadataImplementor){
|
||||
if( StringHelper.isEmpty(getCacheConcurrencyStrategy())){
|
||||
return;
|
||||
}
|
||||
for( EntityBinding entityBinding : metadataImplementor.getEntityBindings()){
|
||||
boolean hasLob = false;
|
||||
for( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure()){
|
||||
if ( attributeBinding.getAttribute().isSingular() ) {
|
||||
Type type = attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping();
|
||||
String typeName = type.getName();
|
||||
if ( "blob".equals( typeName ) || "clob".equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
if ( Blob.class.getName().equals( typeName ) || Clob.class.getName().equals( typeName ) ) {
|
||||
hasLob = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( !hasLob && !entityBinding.getHierarchyDetails().isExplicitPolymorphism() && overrideCacheStrategy() ) {
|
||||
Caching caching = entityBinding.getHierarchyDetails().getCaching();
|
||||
if ( caching == null ) {
|
||||
caching = new Caching();
|
||||
}
|
||||
caching.setRegion( entityBinding.getEntity().getName() );
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( getCacheConcurrencyStrategy() ) );
|
||||
entityBinding.getHierarchyDetails().setCaching( caching );
|
||||
}
|
||||
for( AttributeBinding attributeBinding : entityBinding.getAttributeBindingClosure()){
|
||||
if ( !attributeBinding.getAttribute().isSingular() ) {
|
||||
AbstractPluralAttributeBinding binding = AbstractPluralAttributeBinding.class.cast( attributeBinding );
|
||||
Caching caching = binding.getCaching();
|
||||
if(caching == null){
|
||||
caching = new Caching( );
|
||||
}
|
||||
caching.setRegion( StringHelper.qualify( entityBinding.getEntity().getName() , attributeBinding.getAttribute().getName() ) );
|
||||
caching.setCacheLazyProperties( true );
|
||||
caching.setAccessType( AccessType.fromExternalName( getCacheConcurrencyStrategy() ) );
|
||||
binding.setCaching( caching );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyCacheSettings(Configuration configuration) {
|
||||
if ( getCacheConcurrencyStrategy() != null ) {
|
||||
Iterator itr = configuration.getClassMappings();
|
||||
|
Loading…
x
Reference in New Issue
Block a user