Home > Hibernate > org.hibernate.MappingException: broken column mapping for

org.hibernate.MappingException: broken column mapping for

I got this error when I tried to map a child element by using its parent’s foreign key. I had a parent element with a region id (as foreign key) and I needed to get the child element whose primary key was this region id (and a language id). My child element (Region.hbm.xml) had a composite primary key

  			<key-property name="regionCode" type="integer" column="RGNCDE"/>
  			<key-property name="languageCode" type="integer" column="LNGCDE"/>

and in my parent I did

<property name="regionCode" column="REGCDE" type="integer"/>

<many-to-one name="region" class="my.package.hbm.Region">

but this resulted in “org.hibernate.MappingException: broken column mapping for” error.

I had to split the child’s composite key

<id name="regionCode" type="integer" column="RGNCDE">
			<generator class="assigned"/>

		<property name="languageCode" column="LNGCDE" type="integer"/>

and add a formula property in my parent’s class mapping

<property name="regionCode" column="REGCDE" type="integer"/>

<many-to-one name="region" class="my.package.hbm.Region" formula="REGCDE"/>

so that hibernate could link the region id of the parent to the region id of the child. And since I needed a record based also on the language code (but my parent didn’t have any language code column) I had to manually add search criteria

crit.createCriteria("region").add(Restrictions.eq("languageCode", 1));
Categories: Hibernate
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: