• Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate - Mapping 1 column to multiple properties  RSS feed

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am attempting to map a database column to two properties in a hibernate object (see example below). One of those properties is "read-only".

I would like a foreign key ID column to map to both a property for the ID and a property for the object represented in the foreign key table.

See "property_id" column below in the example. I have marked the mapped property as "insert=false" and "update=false" so you cannot set these values in code.

Unfortunately, Hibernate does not seem to handle this situation. There never is a value for the "property" object. Is this unsupported or am I missing something obvious?



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"

<class name="UTDocPropertyValue" table="doc_property_value" lazy="true">
<id name="id" column="doc_property_value_id">
<generator class="native" />

<property name="documentId" column="document_id" />
<property name="propertyId" column="property_id" />
<property name="propertyValue" column="doc_property_value" />

<many-to-one name="property" column="property_id" insert="false" update="false" class="UTProperty" />

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!