If I have a mapping like this:
<class name="Users" table="users">
<id column="id" name="id">
<generator class="native"/>
</id>
...
<set name="types" table="types" cascade="all">
<key column="user_id" />
<element column="type_name" type="string" />
</set>
</class>
How should the user object be created? I did this:
User u = new User();
u.getType().add(new Type(type_name));
getHibernateTemplate().save(u);
But there will be the error java.lang.ClassCastException: Type
.
The Type class only has an integer user_id
and string type_name
in it with get/set.
Why doesn't it work? Where can I find documentation on saving objects with collection of elements? Thanks you so much.