0

I am trying to persist a table using a hibernate xml mapping file with the id field set as access="noop". I am doing this because I don't want the primary key field to be in the class file. The classes I am persisting are from a third party library and if I change them it will be a maintenance nightmare when the third-party library is updated. I was hoping that I could persist the relations between objects without altering the java class files.

i.e.

<hibernate-mapping>
<class name="blah" table="blah">
        <id name="blah_id" type="long" access="noop" >
            <column name="BLAH_ID" />
            <generator class="native" />
        </id>
        <property name="value" type="double">
            <column name="VALUE" />
        </property>
</class>
</hibernate-mapping>

Unfortunately this doesn't quite work, the noop access specifier requests that hibernate never access the field but hibernate still tries to write a value there when the save function returns causing the following error;

identifier of an instance of third.party.object was altered from 2 to null

I could write a wrapper for the third part libraries, inheriting all the classes and adding the fields for the relations, but I was really hoping for a better solution.

It seems reasonable to want to keep the pks out of the classes. How do I do that?

Any ideas?

1 Answers1

0

I think that component classes are what you're looking for earlier self.