I'm trying to persist an Object which have a set of Strings to database, I found that I must use @ElementCollection to do that, but since I'm using .hbm.xml configuration files through all my project I want to do it using xml .
this question Hibernate, List<String> shows how to do it through annotations, and this link http://en.wikibooks.org/wiki/Java_Persistence/ElementCollection provides tips to do it using xml. But when I tried to use <element-collection> my eclipse IDE didn't accept it and gave me an error at the element <class/> which says the contents of element class must match ...
my class is simply like this
public class Role {
private Long id;
private Integer version;
private String name;
private Set<String> menuItems;
/** getters and setters **/
and my Role.hbm.xml is like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.element.collection.beans">
<class name="Role" table="Role">
<id name="id" type="java.lang.Long" column="id">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">HibernateUniqueKey</param>
<param name="column">NexHiValue</param>
</generator>
</id>
<version name="version" column="Version" />
<property name="name" column="name" type="java.lang.String"
not-null="true" length="128" />
<element-collection name="menuItems">
<collection-table>menuItems</collection-table>
</element-collection>
</class>
update:
here is the last mapping of the set, the rest is not changed
<set name="menuItems" sort="unsorted" table="menuItems" lazy="false">
<key column="itemId" />
<element column="itemName" type="string" />
</set>