HHH-7426 Setting cacheable='true' in orm.xml does not enable caching of entity in 2lc
This commit is contained in:
parent
973451d5e8
commit
97ac8311d4
|
@ -62,7 +62,7 @@ public class JPAMetadataProvider implements MetadataProvider, Serializable {
|
||||||
delegate = new JavaMetadataProvider();
|
delegate = new JavaMetadataProvider();
|
||||||
cache = new HashMap<AnnotatedElement, AnnotationReader>(100);
|
cache = new HashMap<AnnotatedElement, AnnotationReader>(100);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement) {
|
public AnnotationReader getAnnotationReader(AnnotatedElement annotatedElement) {
|
||||||
AnnotationReader reader = cache.get( annotatedElement );
|
AnnotationReader reader = cache.get( annotatedElement );
|
||||||
if (reader == null) {
|
if (reader == null) {
|
||||||
|
@ -76,7 +76,7 @@ public class JPAMetadataProvider implements MetadataProvider, Serializable {
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public Map<Object, Object> getDefaults() {
|
public Map<Object, Object> getDefaults() {
|
||||||
if ( defaults == null ) {
|
if ( defaults == null ) {
|
||||||
defaults = new HashMap<Object, Object>();
|
defaults = new HashMap<Object, Object>();
|
||||||
|
|
|
@ -44,6 +44,7 @@ import javax.persistence.AssociationOverrides;
|
||||||
import javax.persistence.AttributeOverride;
|
import javax.persistence.AttributeOverride;
|
||||||
import javax.persistence.AttributeOverrides;
|
import javax.persistence.AttributeOverrides;
|
||||||
import javax.persistence.Basic;
|
import javax.persistence.Basic;
|
||||||
|
import javax.persistence.Cacheable;
|
||||||
import javax.persistence.CascadeType;
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.CollectionTable;
|
import javax.persistence.CollectionTable;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
|
@ -225,6 +226,7 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
||||||
annotationToXml.put( MapKeyJoinColumn.class, "map-key-join-column" );
|
annotationToXml.put( MapKeyJoinColumn.class, "map-key-join-column" );
|
||||||
annotationToXml.put( MapKeyJoinColumns.class, "map-key-join-column" );
|
annotationToXml.put( MapKeyJoinColumns.class, "map-key-join-column" );
|
||||||
annotationToXml.put( OrderColumn.class, "order-column" );
|
annotationToXml.put( OrderColumn.class, "order-column" );
|
||||||
|
annotationToXml.put( Cacheable.class, "cacheable" );
|
||||||
}
|
}
|
||||||
|
|
||||||
private XMLContext xmlContext;
|
private XMLContext xmlContext;
|
||||||
|
@ -343,6 +345,7 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
||||||
addIfNotNull( annotationList, getSecondaryTables( tree, defaults ) );
|
addIfNotNull( annotationList, getSecondaryTables( tree, defaults ) );
|
||||||
addIfNotNull( annotationList, getPrimaryKeyJoinColumns( tree, defaults, true ) );
|
addIfNotNull( annotationList, getPrimaryKeyJoinColumns( tree, defaults, true ) );
|
||||||
addIfNotNull( annotationList, getIdClass( tree, defaults ) );
|
addIfNotNull( annotationList, getIdClass( tree, defaults ) );
|
||||||
|
addIfNotNull( annotationList, getCacheable( tree, defaults ) );
|
||||||
addIfNotNull( annotationList, getInheritance( tree, defaults ) );
|
addIfNotNull( annotationList, getInheritance( tree, defaults ) );
|
||||||
addIfNotNull( annotationList, getDiscriminatorValue( tree, defaults ) );
|
addIfNotNull( annotationList, getDiscriminatorValue( tree, defaults ) );
|
||||||
addIfNotNull( annotationList, getDiscriminatorColumn( tree, defaults ) );
|
addIfNotNull( annotationList, getDiscriminatorColumn( tree, defaults ) );
|
||||||
|
@ -833,6 +836,21 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
|
||||||
return mergeAttributeOverrides( defaults, attributes, false );
|
return mergeAttributeOverrides( defaults, attributes, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Cacheable getCacheable(Element element, XMLContext.Default defaults){
|
||||||
|
if(element==null)return null;
|
||||||
|
String attValue = element.attributeValue( "cacheable" );
|
||||||
|
if(attValue!=null){
|
||||||
|
AnnotationDescriptor ad = new AnnotationDescriptor( Cacheable.class );
|
||||||
|
ad.setValue( "value", Boolean.valueOf( attValue ) );
|
||||||
|
return AnnotationFactory.create( ad );
|
||||||
|
}
|
||||||
|
if ( defaults.canUseJavaAnnotations() ) {
|
||||||
|
return getJavaAnnotation( Cacheable.class );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Adds a @MapKeyEnumerated annotation to the specified annotationList if the specified element
|
* Adds a @MapKeyEnumerated annotation to the specified annotationList if the specified element
|
||||||
* contains a map-key-enumerated sub-element. This should only be the case for
|
* contains a map-key-enumerated sub-element. This should only be the case for
|
||||||
|
|
|
@ -48,7 +48,7 @@ import org.hibernate.internal.CoreMessageLogger;
|
||||||
*/
|
*/
|
||||||
public class ConnectionProxyHandler
|
public class ConnectionProxyHandler
|
||||||
extends AbstractProxyHandler
|
extends AbstractProxyHandler
|
||||||
implements InvocationHandler, NonDurableConnectionObserver {
|
implements NonDurableConnectionObserver {
|
||||||
|
|
||||||
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class,
|
||||||
ConnectionProxyHandler.class.getName());
|
ConnectionProxyHandler.class.getName());
|
||||||
|
|
|
@ -23,11 +23,18 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.ejb.test.xml;
|
package org.hibernate.ejb.test.xml;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
import javax.persistence.SharedCacheMode;
|
||||||
|
|
||||||
|
import junit.framework.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.ejb.AvailableSettings;
|
||||||
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
import org.hibernate.ejb.test.BaseEntityManagerFunctionalTestCase;
|
||||||
|
import org.hibernate.engine.spi.SessionImplementor;
|
||||||
|
import org.hibernate.persister.entity.EntityPersister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Emmanuel Bernard
|
* @author Emmanuel Bernard
|
||||||
|
@ -39,11 +46,23 @@ public class XmlTest extends BaseEntityManagerFunctionalTestCase {
|
||||||
em.close();
|
em.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testXmlMappingWithCacheable() throws Exception{
|
||||||
|
EntityManager em = getOrCreateEntityManager();
|
||||||
|
SessionImplementor session = em.unwrap( SessionImplementor.class );
|
||||||
|
EntityPersister entityPersister= session.getFactory().getEntityPersister( Lighter.class.getName() );
|
||||||
|
Assert.assertTrue(entityPersister.hasCache());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class[] getAnnotatedClasses() {
|
public Class[] getAnnotatedClasses() {
|
||||||
return new Class[0];
|
return new Class[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void addConfigOptions(Map options) {
|
||||||
|
options.put( AvailableSettings.SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getEjb3DD() {
|
public String[] getEjb3DD() {
|
||||||
return new String[] {
|
return new String[] {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm orm_2_0.xsd"
|
||||||
version="2.0"
|
version="2.0"
|
||||||
>
|
>
|
||||||
<entity class="org.hibernate.ejb.test.xml.Lighter" name="ALighter" access="FIELD" metadata-complete="true">
|
<entity class="org.hibernate.ejb.test.xml.Lighter" cacheable="true" name="ALighter" access="FIELD" metadata-complete="true">
|
||||||
<attributes>
|
<attributes>
|
||||||
<id name="name">
|
<id name="name">
|
||||||
<column name="fld_id"/>
|
<column name="fld_id"/>
|
||||||
|
|
Loading…
Reference in New Issue