はい、XML 経由でこれを行うことができます。私はそれで何の問題も経験しませんでした。このプロジェクトの例を次に示します (このプロジェクトに触れてから長い時間が経過しているため、最小限の作業例を示すためにコードをクリーンアップするつもりはありません)。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.jtalks.common.model.entity.Property" table="PROPERTIES">
<id column="PROPERTY_ID" name="id" unsaved-value="0">
<generator class="native" />
</id>
<property column="UUID" name="uuid" not-null="true" unique="true" />
<property column="NAME" name="name" not-null="true" unique="false" />
<property column="VALUE" name="value" type="text" not-null="false" unique="false" />
<property column="VALIDATION_RULE" name="validationRule" not-null="false" unique="false" />
</class>
</hibernate-mapping>
と:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.jtalks.common.model.entity.Property" table="DEFAULT_PROPERTIES" entity-name="DefaultProperty">
<id column="PROPERTY_ID" name="id" unsaved-value="0">
<generator class="native" />
</id>
<property column="UUID" name="uuid" not-null="true" unique="true" />
<property column="NAME" name="name" not-null="true" unique="false" />
<property column="VALUE" name="value" not-null="false" unique="false" />
<property column="VALIDATION_RULE" name="validationRule" not-null="false" unique="false" />
</class>
</hibernate-mapping>
使用例 #1 を次に示します。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.jtalks.common.model.entity.Component" table="COMPONENTS">
<id column="CMP_ID" name="id" unsaved-value="0">
<generator class="native" />
</id>
<discriminator column="COMPONENT_TYPE" force="false" insert="false" />
<property column="UUID" name="uuid" not-null="true" unique="true" />
<property column="NAME" name="name" not-null="true" unique="true" />
<property column="DESCRIPTION" name="description" />
<bag name="properties" cascade="all-delete-orphan" inverse="false" lazy="false">
<cache usage="nonstrict-read-write" region="org.jtalks.EHCOMMON"/>
<key column="CMP_ID" foreign-key="FK_COMPONENT" />
<one-to-many class="org.jtalks.common.model.entity.Property" />
</bag>
<property name="componentType" column="COMPONENT_TYPE" unique="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.jtalks.common.model.entity.ComponentType</param>
<!-- 12 means 'VARCHAR', see java.sql.Types.VARCHAR -->
<param name="type">12</param>
</type>
</property>
<!-- discriminator - ComponentType.FORUM -->
<subclass name="org.jtalks.poulpe.model.entity.Jcommune" discriminator-value="FORUM">
<list name="sections" cascade="all-delete-orphan" inverse="false" lazy="false">
<cache usage="nonstrict-read-write" />
<key column="COMPONENT_ID" foreign-key="FK_JCOMMUNE" />
<list-index column="POSITION" />
<one-to-many class="org.jtalks.poulpe.model.entity.PoulpeSection" />
</list>
</subclass>
<!-- discriminator - ComponentType.ADMIN_PANEL -->
<subclass name="org.jtalks.poulpe.model.entity.Poulpe" discriminator-value="ADMIN_PANEL" />
<subclass name="org.jtalks.common.model.entity.Component" entity-name="Antarticle" discriminator-value="ARTICLE" />
</class>
</hibernate-mapping>
そして、ここにそれぞれ#2があります:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.jtalks.poulpe.model.entity.ComponentBase" table="BASE_COMPONENTS">
<id column="COMPONENT_TYPE" name="componentType">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.jtalks.common.model.entity.ComponentType</param>
<!-- 12 means 'VARCHAR', see java.sql.Types.VARCHAR -->
<param name="type">12</param>
</type>
</id>
<set name="defaultProperties" cascade="all" inverse="false" lazy="false">
<cache usage="read-only" />
<key column="BASE_COMPONENT_TYPE" foreign-key="COMPONENT_TYPE" />
<one-to-many class="org.jtalks.common.model.entity.Property" entity-name="DefaultProperty" />
</set>
</class>
</hibernate-mapping>
注釈では同じことができないことに注意してください。XML の方が柔軟です。