hibernate對映合成模式的問題
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)
期待各位前輩幫忙解決,或者提出更好的設計方法!
=================================================================
<?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修改過]
相關文章
- hibernate物件對映的一個問題。物件
- 請教一個關於hibernate對映oracle的問題Oracle
- hibernate 元件對映元件
- Hibernate--繼承對映繼承
- Hibernate 的關聯關係對映
- hibernate(五) hibernate一對一關係對映詳解
- Hibernate【對映】知識要點
- hibernate(三) 一對多對映關係
- Docker 埠對映問題解決Docker
- Dozer物件對映框架Map到JSONString對映問題排查物件框架JSON
- Hibernate--單表對映總結
- hibernate 繼承對映關係( JOINED)繼承
- Hibernate繼承對映多型的詳解繼承多型
- Hibernate 對映xml中的屬性型別XML型別
- 資料訪問模式:Identity Map(標識對映)模式模式IDE
- HIBERNATE的自定義型別主鍵的對映??型別
- hibernate(四) 雙向多對多對映關係
- Hibernate對映檔案一對多關係薦
- [Hibernate求助]如何構造自己的對映型別?型別
- Hibernate (開源物件關係對映框架)物件框架
- 關於Beego ORM和 request body 的對映問題GoORM
- resultMap 和 resultType 的欄位對映覆蓋問題
- Hibernate配置檔案中對映元素詳解
- Hibernate的session問題Session
- hibernate 關係對映之 主鍵關聯一對一
- 業務物件對映到表之間的關聯問題!!物件
- LocalSessionFactoryBean載入Hibernate 對映的幾種方式及區別SessionBean
- 學習Hibernate原始碼二_Hibernate物件對映檔案hbm學習原始碼物件
- hibernate 繼承對映關係( SINGLE_TABLE)繼承
- hibernate 繼承對映關係( TABLE_PER_CLASS)繼承
- Middlegen生成Hibernate對映檔案時出錯
- oracle時間欄位預設值,hibernate對映Oracle
- hibernate中的no session問題Session
- 關於URL連結對映到檔案目錄的問題
- 玩轉dnmp之埠對映問題解決方案
- hibernate annotation註解方式來處理對映關係
- Hibernate annotation, JPA如何對映多個屬性為unique
- Hibernate中對映物件應該在service中出現麼?物件