我有兩個需要進行XML映射的類(最終它們都將被修改爲Annotations,但目前我們需要支持XML映射)。休眠映射可選值
我有一個用戶對象,目前看起來是這樣的:
public class User {
private Key key;
private Name name;
}
我需要在選項添加對這些用戶的一些(我們有兩種不同類型的用戶共享同一個對象)。
public class Preferences {
private Person person; //The person key acts as our foreign and primary key
private Integer numToShow;
private String defaultScreenToShow;
}
我的人XML是這樣的:
<hibernate-mapping package="com.example.entities">
<id key column="PERSON_ID" /> <!-- Leaving out custom generator -->
<!--
Not sure what the column needs to be here, as
preferences are in own table. Also read it has to
be a faked out many-to-one here as not all users will
have preferences.
-->
<many-to-one name="preferences" not-null="false" />
<component class="com.example.entities.Name">
<property column="first_name" name="first" />
<property column="last_name" name="last" />
</component>
</hibernate-mapping>
我的喜好XML文件是這樣:
<hibernate-mapping package="com.example.entities">
<property column="default_screen" name="defaultScreenToShow" />
<property column="number_search_results" name="numToShow" />
<!-- Not sure what the ID needs to be here -->
</hibernate-mapping>
我在所有誠實漂亮的綠色與Hibernate,但這似乎就像一些應該很容易映射的東西。我認爲我有正確的映射,但是在嘗試加載一個人時(我將這些類標記爲Serializable - 無濟於事),我得到了反序列化異常。