one-to-many in Hibernate

I am re-factoring one of the internal applications, so that the development can be module based. So my schema has unique module names which has n number of menu items; one-to-many! Here is my hibernate mapping.

<class name="com.eginnovations.common.entity.Module" table="MODULE_INFO">
 <id column="ID" name="id" type="java.lang.Long">
 <generator />
 <property name="moduleName" column="MODULE_NAME" type="java.lang.String"/>
 <property name="enabled" column="ENABLED" type="java.lang.Boolean"/>
 <set name="menuItemList" cascade="all" inverse="true" lazy="false">
 <key column="MODULE_INFO_ID"></key>
<class name="com.eginnovations.common.entity.MenuItem" table="COMMON_MENU">
 <id column="ID" name="id" type="java.lang.Long">
 <generator />
 <property name="menuTitle" column="MENU_TITLE" type="java.lang.String"/>
 <property name="parentId" column="PARENT_MENU_ID" type="java.lang.Long"/>
 <property name="locationHref" column="LOCATION_HREF" type="java.lang.String"/>
 <many-to-one name="module" column="MODULE_INFO_ID" cascade="all"></many-to-one>

But when I run the unit test to get the list of modules, I ended up with the exception

org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException
occurred while calling setter of com.eginnovations.common.entity.Module.menuItemList;
nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException
occurred while calling setter of com.eginnovations.common.entity.Module.menuItemList
at org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(
 at org.springframework.orm.hibernate3.HibernateAccessor.convertHibernateAccessException(

The problem is with data type, the menuItemList is mapped to a list instead of a set!!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s