JPA中的@Basic(可选= false)vs @Column(nullable = false) [英] @Basic(optional = false) vs @Column(nullable = false) in JPA

查看:1105
本文介绍了JPA中的@Basic(可选= false)vs @Column(nullable = false)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JPA中 @Basic(可选= false) @Column(nullable = false)之间的区别是什么持久性?

What's the difference between @Basic(optional = false) and @Column(nullable = false) in JPA persistence?

推荐答案

Gordon Yorke(EclipseLink架构委员会成员,TopLink核心技术主管,JPA 2.0专家组成员)写了一个很好的答案关于这个主题所以我没有复述他,而是引用他的回答

Gordon Yorke (EclipseLink Architecture Committee Member, TopLink Core Technical Lead, JPA 2.0 Expert Group Member) wrote a good answer on this topic so instead of paraphrasing him, I'll quote his answer:


可选
之间的差异可以为空是他们
的评估范围。
' optional '的定义讨论了属性和
字段值,并建议应该在$ b $内评估这个
特性b运行时。 ' nullable '仅在对数据库列的
引用中。

The difference between optional and nullable is the scope at which they are evaluated. The definition of 'optional' talks about property and field values and suggests that this feature should be evaluated within the runtime. 'nullable' is only in reference to database columns.

如果某个实现选择
实现可选那么那些
属性应该在持久性提供程序的
内存和
在向数据库发送
之前引发的异常,否则当使用
' updatable = false ''可选'
违规将永远不会被报告。

If an implementation chooses to implement optional then those properties should be evaluated in memory by the Persistence Provider and an exception raised before SQL is sent to the database otherwise when using 'updatable=false' 'optional' violations would never be reported.

这篇关于JPA中的@Basic(可选= false)vs @Column(nullable = false)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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