[英]Hibernate noop id primary keys
I am trying to persist a table using a hibernate xml mapping file with the id field set as access="noop". 我试图使用ID字段设置为access =“ noop”的休眠xml映射文件来持久保存表。 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.
我希望可以在不更改java类文件的情况下保持对象之间的关系。
ie 即
<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; 不幸的是,这还行不通,noop访问说明符请求休眠状态从不访问该字段,但是当保存函数返回导致以下错误时,休眠状态仍然尝试在其中写入值;
identifier of an instance of third.party.object was altered from 2 to null third.party.object实例的标识符从2更改为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. 想要将pks排除在类之外似乎是合理的。 How do I do that?
我怎么做?
Any ideas? 有任何想法吗?
我认为组件类是您正在寻找的较早的自我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.