开发者

Hibernate map declared in abstract class not inherited in subclasses

开发者 https://www.devze.com 2023-03-29 02:58 出处:网络
I have an abstract class A and two classes B and C implementing A. abstract class A implements Serializable {

I have an abstract class A and two classes B and C implementing A.

abstract class A implements Serializable {
  Long id
  String code
  String description
  Map<Locale, String> localizedDescriptions 
}

class B implements A {}

class C implements A {}

With the following hibernate mapping:

<class name="A" abstract="true">

    <id name="id">
        <generator class="org.hibernate.id.enhanced.TableGenerator"/>
    </id>

    <property name="code" unique="true" not-null="true"/>
    <property name="description" not-null="true"/>

    <map 开发者_如何学编程name="localizedDescriptions" lazy="false">
        <key property-ref="code" column="code"/>
        <index column="locale" type="locale"/>
        <element column="description" type="string" not-null="true"/>
    </map>

    <union-subclass name="B"/>
    <union-subclass name="C"/>

The B and C database tables I get have the fields id, code and description as expected. However there are no b_localized_descriptions or c_localized_descriptions tables but there's a a_localized_descriptions table, which isn't what I want. So, is it possible to have the desired behaviour without having to define the map for every subclass ?


<union-subclass name=”C”>
<property name=”salary” column=”SALARY” />
<property name=”bonus” column=”BONUS” />
</union-subclass>

Specify the properties within the union subclass xml tag that you would like included.

0

精彩评论

暂无评论...
验证码 换一张
取 消