我有一个想要通过 Hibernate 持久保存的实体 (3.2) EntityBean 有一个列,指示应如何解码实体 bean 的另一个值:
<class name="ServiceAttributeValue" table="service_attribute_value">
<cache usage="nonstrict-read-write"/>
<id name="id" column="id" type="int-long">
<generator class="native"/>
</id>
<property name="serviceAttribute" type="service-attribute" column="service_attribute" not-null="true" />
<!-- order is important here -->
<property name="value" type="attribute-value" not-null="true">
<column name="service_attribute" />
<column name="id_value"/>
<column name="enum_value"/>
<column name="string_value"/>
<column name="int_value"/>
<column name="boolean_value"/>
<column name="double_value"/>
</property>
</class>
“service_attribute”列指示在解码值时要查看“value”属性的哪一列,更重要的是,该值的确切类型,例如,如果 enum_value 是 Enum 的类要读取的值,如果要读取 id_value,则为 Bean 的类型。
value 属性使用自定义 CompositeUserType 进行解码,在其中我希望引用 service_attribute 列(尽管不写入它),但是当我尝试执行此操作时,出现以下错误:
org.hibernate.MappingException: Repeated column in mapping for entity: com.precurse.apps.rank.model.service.ServiceAttributeValue column: service_attribute (should be mapped with insert="false" update="false")
但是,在复合属性的定义中,未定义这些 xml 属性(仅在普通属性中)。
有谁知道解决这个问题的方法,或者是否有更好的解决方案。
如果您需要更多信息,请告诉我,
干杯 西蒙
最佳答案
我遇到了类似的问题,更改一列的大小写解决了问题。可以尝试一下!
例如,一列可以是 service_attribute 其他 Service_Attribute。
关于java - Hibernate Reference 表中的列指示如何解码同一表中不同列中的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2244747/