@ManyToOne(可选= false)和@Column(nullable = false)有什么区别? [英] What is the difference between @ManyToOne(optional=false) vs. @Column(nullable=false)

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

问题描述

在JPA中,我很困惑何时使用属性 optional = false 和注释 @Column(nullable = false)。有什么区别?

In JPA, I am confused when to use the attribute optional=false and the annotation @Column(nullable=false). What is the difference?

推荐答案

@Column(nullable = false)是用于生成模式的指令。在实际数据库中,生成在类外的数据库列将被标记为不可空。

@Column(nullable=false) is an instruction for generating the schema. The database column generated off the class will be marked not nullable in the actual database.

可选= false 是运行时指令。它所做的主要功能与延迟加载有关。除非你记得设置optional = false(因为Hibernate不知道应该有一个代理还是一个null,除非你告诉它空值是不可能的,所以它可以产生一个非集合映射实体一个代理。)

optional=false is a runtime instruction. The primary functional thing it does is related to Lazy Loading. You can't lazy load a non-collection mapped entity unless you remember to set optional=false (because Hibernate doesn't know if there should be a proxy there or a null, unless you tell it nulls are impossible, so it can generate a proxy.)

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

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