当其子对象的状态更改时,父对象的版本不会更改

编程入门 行业动态 更新时间:2024-10-09 06:28:14
本文介绍了当其子对象的状态更改时,父对象的版本不会更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Hibernate3 我有一个简单的一对多关系(父对象具有子对象集) 如果添加/删除了子对象,则会更新父对象的版本,就像子对象的状态已更改一样,父对象的版本也不会得到更新.

I am using Hibernate3 I have a simple one to many relationship(Parent object has as set of child objects) if the child objects are added/removed, the version of the parent object is updated where as if the state of the child object is changed, the version of the parent is not getting updated.

这里是映射- Category.hbm.xml

Here is the mapping - Category.hbm.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "www.hibernate/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="net.codejava.hibernate"> <class name="Category" table="CATEGORY"> <id name="id" column="CATEGORY_ID"> <generator class="native"/> </id> <property name="name" column="NAME" /> <version name="version" type="integer" column="version" unsaved-value="null" /> <set name="products" inverse="true" cascade="all-delete-orphan"> <key column="CATEGORY_ID" not-null="true" /> <one-to-many class="Product"/> </set> </class>

Product.hbm.xml

Product.hbm.xml

<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "www.hibernate/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="net.codejava.hibernate"> <class name="Product" table="PRODUCT"> <id name="id" column="PRODUCT_ID"> <generator class="native"/> </id> <version name="version" type="integer" column="version" unsaved-value="null" /> <property name="name" column="NAME" /> <property name="description" column="DESCRIPTION" /> <property name="price" column="PRICE" type="float" /> <many-to-one name="category" class="Category" column="CATEGORY_ID" not-null="true"/> </class>

产品更改时,Product.version会正确更新,但Category.version保持不变.

When the Product changes, Product.version is updated properly but the Category.version remains the same.

我认为这是一个跨领域的问题,必须为此提供一个可行的解决方案.我做了很多搜索,却找不到.请帮帮我

I assume this is a cross cutting concern and there has to be a plausible solution for this. I did a lot of searching and could not find one. Please help me out

推荐答案

是的,恐怕这只是休眠方式的限制.唯一的解决方案是在需要进行更改时在两侧都进行更改.

Yes, this is just a limitation of the way hibernate works, I'm afraid. The only solution is to change it on both sides when you need to make a change.

您还可以刷新父级,但请记住,这将影响数据库.

You could also refresh the parent, but bear in mind that that will hit the database.

更多推荐

当其子对象的状态更改时,父对象的版本不会更改

本文发布于:2023-11-05 10:09:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   其子   状态   版本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!