0

I mapped following map collection:

<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>

This works great; all records are added to the map if columns 'primary_id', 'custom_id' and 'other_id' are all filled with a value.

But when 'other_id' column is empty, that record is not added to the map. Is there a property or something I can force Hibernate to add these records to the Java Map as well?

Visualisation

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

2 Answers 2

1

After long searching documentations and such, I just found out that Hibernate does not support NULL values in a map:

Sign up to request clarification or add additional context in comments.

Comments

0

Try adding the not-null="false" in your mapping

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

1 Comment

I don't think a not-null attribute is allowed. If I add one, i stumble upon a Attribute "not-null" must be declared for element type "many-to-many" error!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.