This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

Hibernate - Mapping 1 column to multiple properties

Brent Cromley

Joined: Oct 25, 2004
Posts: 3

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

I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Hibernate - Mapping 1 column to multiple properties
It's not a secret anymore!