hibernate映射合成模式的问题

09-03-03 zidom
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修改过]

banq
2009-03-04 11:25
> An association from the table principal refers to an unmapped class: GroupModel

看错误调试是编程基本功,这里意思是GroupModel这个类没有进行映射配置。

猜你喜欢