没有一列的Hibernate保存对象 [英] Hibernate Save Object without one column

查看:223
本文介绍了没有一列的Hibernate保存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为test的表,它有像id,name,address这样的列。我为所有三列创建了POJO类( User ),并且已经使用hbm配置映射了它。

I have a table called test and It has columns like id, name, address. I have created POJO class(User) for all the three columns and same has been mapped with hbm configuration.

这里我的问题是,如何在保存会话( session.save(User))中的User对象时阻止一列。

Here My questions is, How do I prevent one column while saving the User object in session (session.save(User)).

假设我不想保存我的地址栏。我该如何预防。有没有HIbernate配置中的任何属性或需要在POJO中添加任何修饰符?

Let say I dont want to save my address field. How can I prevent. Are there any properties in HIbernate configuration or any modifier needs to be added in POJO?

推荐答案

将该字段设置为Transient。

Make that field as Transient.

Transient - 如果它刚刚使用new运算符实例化,则它是暂时的,并且它与Hibernate Session没有关联。它在数据库中没有持久表示并且没有分配标识符值。如果应用程序不再拥有引用,则垃圾收集器将销毁瞬态实例。使用Hibernate Session使对象持久化(并让Hibernate处理需要为此转换执行的SQL语句)。

Transient - an object is transient if it has just been instantiated using the new operator, and it is not associated with a Hibernate Session. It has no persistent representation in the database and no identifier value has been assigned. Transient instances will be destroyed by the garbage collector if the application does not hold a reference anymore. Use the Hibernate Session to make an object persistent (and let Hibernate take care of the SQL statements that need to be executed for this transition).

https://docs.jboss.org/hibernate/orm/3.3/reference/en /html/objectstate.html

这篇关于没有一列的Hibernate保存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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