Normally we store a List in database by the hibernate mapping:
<list name="userItems" cascade="all" lazy="false">
<key column="user_date_id"/>
<index column="idx"/>
<one-to-many class="UserItem"/>
</list>
Is there any other way? Can we store it as a Seializable object? Like:
<property name="list" column="list" type="serializable" />
I use Hibernate Annotiations, and the trick here is to define your field as a
Listimplementation likeArrayList. Then (like any other class implementingSerializable– i guess) Hibernate stores it as abyteain the database.Of course the list should only contain elements that implement
Serializable.