不向数据库提交hibernate实体字段 [英] Not committing an hibernate entity field to the DB

查看:269
本文介绍了不向数据库提交hibernate实体字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含几个字段的基本hibernate实体。
当前所有字段都使用@column注释进行注释,并且数据库scheam也相应地对应。



现在,我想要做的是删除数据库中的字段,但保留在实体中(它只是用于一些验证,它不应该写入数据库)。



所以我已经更新我的数据库scheam,但我应该如何处理我的实体?
我应该简单地从字段中删除@column注释,还是有一个特殊的jpa注释将字段从crud操作中排除?

预先感谢!

解决方案

在实体类中为属性注释为 @Transient ,并移除 @Column 注释。


I have a basic hibernate entity which contains a few fields. Currently all the fields are annotated with the @column annotation and the DB scheam corresponds accordingly.

Now, what I would like to do is to remove one of the fields from the DB but to keep it in the entity (it is only required for some validations, it should not be written to the DB).

So I have updated my DB scheam but what should I do with my entity? Should I simply remove the @column annotation from the field or is there a spesific jpa annotation that exclude the field from the crud operations?

Thanks in advance!

解决方案

Annotate the attribute in your entity class as @Transient and remove the @Column annotation.

这篇关于不向数据库提交hibernate实体字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆