2010-06-08 69 views
3

我想将polymorphism="explicit"属性设置为多个hibernate映射类。是否可以重写默认的implicit值,以便我不需要在多个类中设置explicit更改Hibernate中的默认多态性

<class name="xxxxx" table="XXXXX" polymorphism="explicit"> 

我使用Hibernate映射XML文件(没有说明或JPA),它是由弹簧加载如下,

<bean id="xxxsessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> 
    <property name="dataSource"> 
     <ref bean="xxxDataSource"/> 
    </property> 
    <property name="mappingResources"> 
     <list> 
      <value>xxx.hbm.xml</value> 
      -------- 
      -------- 
     </list> 
    </property> 
    <property name="hibernateProperties"> 
     <props> 
      <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> 
      ---- 
      ---- 
     </props> 
    </property> 
</bean> 

谢谢。

回答

0

浏览hibernate源代码,看起来好像没有办法绕过这个限制。

的休眠核心类似乎通过调用各种isExplicitPolymorphism()方法,这一切似乎都归结为org.hibernate.mapping.PersistentClass.isExplicitPolymorphism()方法确定多态性设置。从此方法返回的值设置为org.hibernate.mapping.RootClass.setExplicitPolymorphism()方法。仅在org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues()(用于XML配置)和org.hibernate.cfg.annotations.EntityBinder.bindEntity()(用于注释配置)方法中调用此方法。

我没有看到为映射文件中的所有实体设置ploymorphism=explicit的方法。