gpt4 book ai didi

hibernate - 更改 Hibernate 中的默认多态性

转载 作者:行者123 更新时间:2023-12-02 22:24:46 24 4
gpt4 key购买 nike

我想将 polymorphism="explicit" 属性设置为几个 Hibernate 映射类。是否可以覆盖默认的隐式值,以便我不需要在多个类中设置显式

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

我正在使用 hibernate 映射 xml 文件(无注释或 JPA),它由 Spring 加载,如下所示,

<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>

谢谢。

最佳答案

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

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 的方法。

关于hibernate - 更改 Hibernate 中的默认多态性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2996153/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com