diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java index 8fbd1780b..bc9758cd6 100755 --- a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java +++ b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/PojoInstantiator.java @@ -17,6 +17,7 @@ import com.fr.third.org.hibernate.internal.CoreLogging; import com.fr.third.org.hibernate.internal.CoreMessageLogger; import com.fr.third.org.hibernate.internal.util.ReflectHelper; import com.fr.third.org.hibernate.mapping.Component; +import com.fr.third.org.hibernate.tuple.entity.DefaultEntityRegister; /** * Defines a POJO-based instantiator for use from the tuplizers. @@ -72,7 +73,11 @@ public class PojoInstantiator implements Instantiator, Serializable { public Object instantiate() { if ( isAbstract ) { - throw new InstantiationException( "Cannot instantiate abstract class or interface: ", mappedClass ); + try { + return DefaultEntityRegister.getInstance().getDefaultEntityClass(mappedClass).newInstance(); + } catch (Exception e) { + throw new InstantiationException("class not found: ", mappedClass); + } } else if ( optimizer != null ) { return optimizer.newInstance(); diff --git a/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java new file mode 100644 index 000000000..ec7de7b57 --- /dev/null +++ b/fine-hibernate/src/com/fr/third/org/hibernate/tuple/entity/DefaultEntityRegister.java @@ -0,0 +1,40 @@ +package com.fr.third.org.hibernate.tuple.entity; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Created by Zed on 2018/11/1. + */ +public class DefaultEntityRegister { + + private static volatile DefaultEntityRegister instance; + private static Map MAP = new ConcurrentHashMap(); + + public static DefaultEntityRegister getInstance() { + if (instance == null) { + synchronized (DefaultEntityRegister.class) { + if (instance == null) { + instance = new DefaultEntityRegister(); + } + } + } + return instance; + } + + private DefaultEntityRegister() { + + } + + public void registerDefaultClass(Class abstractEntityClass, Class defaultEntityClass) { + MAP.put(abstractEntityClass, defaultEntityClass); + } + + public void removeDefaultClass(Class abstractEntityClass) { + MAP.remove(abstractEntityClass); + } + + public Class getDefaultEntityClass(Class abstractEntityClass) { + return MAP.get(abstractEntityClass); + } +}