本文介绍了休眠:插入/更新时的自定义代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的休眠对象,尝试评估我是否可以将其实际用于我的项目.一种类型的实体需要对插入或更新进行一些特殊检查.我将尝试解释得尽可能简单.可以说我们有颜色.用户可以创建n种颜色的混合并将该混合存储在数据库中.稍后,如果用户搜索蓝色"颜色,则应显示所有包含蓝色的混合物.

I'm new to hibernate and trying to evaluate if I can actually use it for my project. One type of entity needs to do some special checks on insert or update. I'm going to try to explain as easy as possible. Lets say we have colors. A user can create a Mixture of n colors and store that mixture in the database. Later if a user searches for color "blue" all Mixtures containing blue should be displayed.

业务规则是任何颜色只能在数据库中出现一次.因此,如果插入了新的混合物,则必须首先检查数据库中是否已经存在所有颜色,如果是,则应重新使用(引用)该颜色,如果不是,则应创建新的颜色.

Business rule is that any color should only be in the database once. So if a new mixture is inserted, it must first be checked if all the colors are already in the database and if yes that color should be reused (referenced) and if not a new one should be created.

如果更改混合物,例如将蓝色"替换为红色",则行为必须是保持原始的蓝色"不变,并且系统检查红色"是否存在,然后重新使用或创建它,然后添加混合起来.

If a mixture is changed say "blue" is replaced with "red", the behavior must be that the initial "blue" remains untouched and the system checks if "red" exists and either reuses it or creates it and then adds it to the mixture.

我该如何使用休眠模式?

How can i do this with hibernate?

推荐答案

您可以做到,但是Hibernate并没有很多.

You can do it, but that does not have a lot with Hibernate.

您描述的内容是服务类应该完成的事情.

The stuff which you describe is something what should be done by your service classes.

这应该是您应用程序的逻辑,而不是ORM工具应该做的事情.

This should be logic of your application, not something what ORM tool should do.

听力是您可以阅读有关休眠事件的链接.

Hear is link where you can read about Hibernate events

这篇关于休眠:插入/更新时的自定义代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 05:03
查看更多