hibernate對映合成模式的問題

zidom發表於2009-03-03
Principal是一個抽象類,其子類有:GroupModel、UserModel,GroupModel中可以包含一個或者多個Principal,一下是我的對映檔案:

=================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class lazy="true" name="xhlh.ac.Principal" table="principal"
polymorphism="explicit">
<id column="id" length="32" name="id" type="string">
<generator class="uuid" />
</id>
<property generated="never" lazy="false" length="64" name="name"
not-null="true" type="string" unique="true" />
<property generated="never" lazy="false" name="creationDate"
type="timestamp" />
<property generated="never" lazy="false" name="description"
type="text" />
<map name="properties" table="principal_prop" cascade="all" fetch="join"
lazy="false">
<key column="uid" />
<map-key column="name" type="string" />
<element column="value" type="text" />
</map>
<many-to-one class="GroupModel" column="groupid" fetch="join"
lazy="proxy" name="group" />
<set name="roles" table="user_role" lazy="true">
<key column="uid" />
<many-to-many class="RoleModel" column="roleid" unique="false" />
</set>
</class>
<joined-subclass name="xhlh.domain.GroupModel" table="group_model"
extends="xhlh.ac.Principal">
<key column="gid" />
<set name="members" lazy="true">
<key column="groupid" />
<one-to-many class="xhlh.ac.Principal" />
</set>
</joined-subclass>
<joined-subclass name="xhlh.domain.UserModel" table="user_model"
extends="xhlh.ac.Principal">
<key column="uid" />
<property generated="never" lazy="false" length="64" name="loginName"
not-null="true" type="string" />
<property generated="never" lazy="false" length="32" name="password"
not-null="true" type="string" />
<property column="isGroupAdmin" generated="never" lazy="false"
name="groupAdmin" type="boolean" />
</joined-subclass>
</hibernate-mapping>
=================================================================

我用new SchemaExport(config).create(true, true);匯出表時丟擲異常:
Exception in thread "main" org.hibernate.MappingException: An association from the table principal refers to an unmapped class: GroupModel
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1252)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1260)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1260)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1170)
at org.hibernate.cfg.Configuration.generateDropSchemaScript(Configuration.java:756)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:93)
at org.hibernate.tool.hbm2ddl.SchemaExport.<init>(SchemaExport.java:61)
at xhlh.ExportDB.main(ExportDB.java:10)
期待各位前輩幫忙解決,或者提出更好的設計方法!

[該貼被zidom於2009-03-03 15:38修改過]

[該貼被zidom於2009-03-03 15:39修改過]

[該貼被zidom於2009-03-03 15:58修改過]

[該貼被admin於2009-03-04 11:23修改過]

相關文章