HHH-5916 Use PersisterClassProvider in Binders
This commit is contained in:
parent
55eb37ed52
commit
4ffba763cf
|
@ -86,6 +86,9 @@ import org.hibernate.mapping.TypeDef;
|
|||
import org.hibernate.mapping.UnionSubclass;
|
||||
import org.hibernate.mapping.UniqueKey;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.persister.PersisterClassProvider;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
|
||||
import org.hibernate.persister.entity.SingleTableEntityPersister;
|
||||
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
|
||||
|
@ -681,6 +684,9 @@ public final class HbmBinder {
|
|||
entity.setMetaAttributes( getMetas( node, inheritedMetas ) );
|
||||
|
||||
// PERSISTER
|
||||
//persister node in XML has priority over
|
||||
//persisterClassProvider
|
||||
//if all fail, the default Hibernate persisters kick in
|
||||
Attribute persisterNode = node.attribute( "persister" );
|
||||
if ( persisterNode != null ) {
|
||||
try {
|
||||
|
@ -692,6 +698,17 @@ public final class HbmBinder {
|
|||
+ persisterNode.getValue() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||
if ( persisterClassProvider != null ) {
|
||||
final Class<? extends EntityPersister> persister = persisterClassProvider.getEntityPersisterClass(
|
||||
entity.getEntityName()
|
||||
);
|
||||
if ( persister != null ) {
|
||||
entity.setEntityPersisterClass( persister );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CUSTOM SQL
|
||||
handleCustomSQL( node, entity );
|
||||
|
@ -1380,6 +1397,9 @@ public final class HbmBinder {
|
|||
|
||||
|
||||
// PERSISTER
|
||||
//persister node in XML has priority over
|
||||
//persisterClassProvider
|
||||
//if all fail, the default Hibernate persisters kick in
|
||||
Attribute persisterNode = node.attribute( "persister" );
|
||||
if ( persisterNode != null ) {
|
||||
try {
|
||||
|
@ -1391,6 +1411,16 @@ public final class HbmBinder {
|
|||
+ persisterNode.getValue() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||
if ( persisterClassProvider != null ) {
|
||||
final Class<? extends CollectionPersister> persister =
|
||||
persisterClassProvider.getCollectionPersisterClass( collection.getRole() );
|
||||
if ( persister != null ) {
|
||||
collection.setCollectionPersisterClass( persister );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Attribute typeNode = node.attribute( "collection-type" );
|
||||
if ( typeNode != null ) {
|
||||
|
|
|
@ -107,6 +107,8 @@ import org.hibernate.mapping.Selectable;
|
|||
import org.hibernate.mapping.SimpleValue;
|
||||
import org.hibernate.mapping.SingleTableSubclass;
|
||||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.persister.PersisterClassProvider;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.util.StringHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
|
@ -397,8 +399,23 @@ public abstract class CollectionBinder {
|
|||
collection.setMutable( !property.isAnnotationPresent( Immutable.class ) );
|
||||
OptimisticLock lockAnn = property.getAnnotation( OptimisticLock.class );
|
||||
if ( lockAnn != null ) collection.setOptimisticLocked( !lockAnn.excluded() );
|
||||
|
||||
//@Persister has priority over PersisterClassProvider
|
||||
//if all fail, left null and Hibernate defaults kick in
|
||||
Persister persisterAnn = property.getAnnotation( Persister.class );
|
||||
if ( persisterAnn != null ) collection.setCollectionPersisterClass( persisterAnn.impl() );
|
||||
if ( persisterAnn != null ) {
|
||||
collection.setCollectionPersisterClass( persisterAnn.impl() );
|
||||
}
|
||||
else {
|
||||
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||
if (persisterClassProvider != null) {
|
||||
final Class<? extends CollectionPersister> persister =
|
||||
persisterClassProvider.getCollectionPersisterClass( collection.getRole() );
|
||||
if (persister != null) {
|
||||
collection.setCollectionPersisterClass( persister );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// set ordering
|
||||
if ( orderBy != null ) collection.setOrderBy( orderBy );
|
||||
|
|
|
@ -82,6 +82,7 @@ import org.hibernate.mapping.SimpleValue;
|
|||
import org.hibernate.mapping.Table;
|
||||
import org.hibernate.mapping.TableOwner;
|
||||
import org.hibernate.mapping.Value;
|
||||
import org.hibernate.persister.PersisterClassProvider;
|
||||
import org.hibernate.util.ReflectHelper;
|
||||
import org.hibernate.util.StringHelper;
|
||||
import org.jboss.logging.Logger;
|
||||
|
@ -243,6 +244,8 @@ public class EntityBinder {
|
|||
|
||||
//set persister if needed
|
||||
//@Persister has precedence over @Entity.persister
|
||||
//in both fail we look for the PersisterClassProvider
|
||||
//if all fail, the persister is left null and the Hibernate defaults kick in
|
||||
Persister persisterAnn = annotatedClass.getAnnotation( Persister.class );
|
||||
Class persister = null;
|
||||
if ( persisterAnn != null ) {
|
||||
|
@ -258,8 +261,16 @@ public class EntityBinder {
|
|||
throw new AnnotationException( "Could not find persister class: " + persister );
|
||||
}
|
||||
}
|
||||
else {
|
||||
final PersisterClassProvider persisterClassProvider = mappings.getPersisterClassProvider();
|
||||
if ( persisterClassProvider != null ) {
|
||||
persister = persisterClassProvider.getEntityPersisterClass( persistentClass.getEntityName() );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( persister != null ) {
|
||||
persistentClass.setEntityPersisterClass( persister );
|
||||
}
|
||||
if ( persister != null ) persistentClass.setEntityPersisterClass( persister );
|
||||
|
||||
persistentClass.setBatchSize( batchSize );
|
||||
|
||||
|
|
Loading…
Reference in New Issue