我正在構建數據倉庫並希望使用InfiniDB作爲存儲引擎。但是,它不允許使用主鍵或外鍵約束(或對此有任何約束)。休眠沒有主鍵生成的數據庫?
Hibernate抱怨當我執行插入操作時,「數據庫沒有返回本地生成的標識值」。
每個表都是關係型的,並且包含一個以前用作主鍵的唯一整數列 - 我想保留這一點,但是沒有db中的約束條件,即該列是主鍵。
我假設問題是Hibernate希望數據庫返回一個生成的密鑰。是否有可能重寫這種行爲,所以我可以自己設置主鍵字段的值,並保持休眠快樂?
- 編輯 -
映射的兩個如下:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 1, 2010 2:49:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="com.example.project.Visitor" table="visitor" catalog="orwell">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="identity" />
</id>
<property name="firstSeen" type="timestamp">
<column name="first_seen" length="19" />
</property>
<property name="lastSeen" type="timestamp">
<column name="last_seen" length="19" />
</property>
<property name="sessionId" type="string">
<column name="session_id" length="26" unique="true" />
</property>
<property name="userId" type="java.lang.Long">
<column name="user_id" />
</property>
<set name="visits" inverse="true">
<key>
<column name="visitor_id" />
</key>
<one-to-many class="com.example.project.Visit" />
</set>
</class>
</hibernate-mapping>
和:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jun 1, 2010 2:49:51 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="com.example.project.Visit" table="visit" catalog="orwell">
<id name="id" type="java.lang.Long">
<column name="id" />
<generator class="identity" />
</id>
<many-to-one name="visitor" class="com.example.project.Visitor" fetch="join" cascade="all">
<column name="visitor_id" />
</many-to-one>
<property name="visitId" type="string">
<column name="visit_id" length="20" unique="true" />
</property>
<property name="startTime" type="timestamp">
<column name="start_time" length="19" />
</property>
<property name="endTime" type="timestamp">
<column name="end_time" length="19" />
</property>
<property name="userAgent" type="string">
<column name="user_agent" length="65535" />
</property>
<set name="pageViews" inverse="true">
<key>
<column name="visit_id" />
</key>
<one-to-many class="com.example.project.PageView" />
</set>
</class>
</hibernate-mapping>
我假設我可以使用「賦值」生成器類,但是如果我有一個包含外鍵關係(但沒有約束)的表的一個表沒有主關鍵約束? – 2010-06-08 15:04:12
您可以顯示實際DTO類的映射嗎? – Espen 2010-06-08 15:17:18
@Espen - 完成 – 2010-06-08 15:26:08