GeeCON Prague 2014*
The moose likes Object Relational Mapping and the fly likes Hibernate - Mapping 1 column to multiple properties Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate - Mapping 1 column to multiple properties" Watch "Hibernate - Mapping 1 column to multiple properties" New topic
Author

Hibernate - Mapping 1 column to multiple properties

Brent Cromley
Greenhorn

Joined: Oct 25, 2004
Posts: 3
Hi,

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?

Thanks,

Brent


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

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

<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" />

</class>
</hibernate-mapping>
 
GeeCON Prague 2014
 
subject: Hibernate - Mapping 1 column to multiple properties