2016-02-19 88 views
0

我映射下列地圖收集:休眠NULL值(XML映射)

<map name="customFields" table="table_name" fetch="select"> 
    <key column="primary_id" /> 
    <map-key-many-to-many column="custom_id" class="CustomField" /> 
    <many-to-many column="other_id" class="AnotherClass" /> 
</map> 

這個偉大的工程;如果列'primary_id','custom_id'和'other_id'都填充了一個值,則所有記錄都會添加到地圖中。

但是,當'other_id'列爲空時,該記錄不會添加到地圖中。有沒有一個屬性或者我可以強迫Hibernate將這些記錄添加到Java Map?

可視化

+------------+-----------+----------+ 
| primary_id | custom_id | other_id | Added? 
+------------+-----------+----------+ 
|   1 |  53 | 124  | YES 
|   2 |  98 | 288  | YES 
|   3 |  18 | NULL  | NO  
+------------+-----------+----------+ 

回答

0

嘗試添加非空= 「假」 在映射

<many-to-many column="other_id" not-null="false" class="AnotherClass" />

+0

我不認爲'不,null'屬性是允許的。如果我添加一個,我偶然發現一個'Attribute「not-null」必須聲明爲元素類型「多對多」錯誤! –