【问题标题】:How can I insert Null value in the entity (EJB3)?如何在实体 (EJB3) 中插入 Null 值?
【发布时间】:2012-06-21 17:35:35
【问题描述】:

我正在研究 EJB3。我想在表中插入 Null 值。

例如。我有一个名为“Students”的表,其中包含列字段,例如

String name;
String class;
Set<Subjects> subjects;

subjects 字段具有 JoinTable "student_subjects" 字段 joinColumns "student_name" 的 "Students" 表和 inverseJoinColumns "subjects_name" 的 "subjects" 表

我想要的是当我添加一个新学生时,“学生”表中会有一个条目。

也在“student_subjects”表中。但对于“subjects_name”,值必须是 student_name(非空)和 NULL。有可能吗?

【问题讨论】:

    标签: ejb entity ejb-3.0 entity-relationship ejb-3.1


    【解决方案1】:

    您需要使用@Column JPA 注解的nullable 属性。

    @Column(nullable = false)
    private String studentName;
    
    @Column(nullable = true)
    private String subjectsName;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-19
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-25
      • 2021-02-08
      相关资源
      最近更新 更多