简体   繁体   English

应该映射为insert =“ false” update =“ false”

[英]should be mapped with insert=“false” update=“false”

I got the next 2 classes : 我参加了下两节课:

@Entity
@Table(name="questions")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="is_sponsered")
@SequenceGenerator(name="id_seq")
  public class Question {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="id_seq")
protected int id;

@Column(name="is_sponsered",nullable=false)
protected boolean sponsered=false;

....}

and a subclass : 和一个子类:

@Entity
@DiscriminatorValue("true")

public class SP extends Question{

public SP(String q)
{
    super(q);
    this.sponsered=true;
}

However, I'm getting the next error : 但是,我遇到下一个错误:

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: SP column: is_sponsered 

From what I understood insertable=false and updatble=false is often used when we have a OneToMany relation. 据我了解,当我们具有OneToMany关系时,经常使用insertable = false和updatble = false。 In this case its just inheritance. 在这种情况下,它只是继承。 When adding the insertabl=false,updtable=false to the column sponsered in the Question class the error doesnt appear. 将insertabl = false,updtable = false添加到在Question类中响应的列时,不会出现错误。 I wanted to understand why.. 我想知道为什么。

When you need to map the discriminator column, you'll have to map it with insert="false" update="false" because it is only Hibernate that manages the column. 当需要映射鉴别符列时,必须使用insert="false" update="false"映射它,因为只有Hibernate才能管理该列。 If you don't map the column, Hibernate considers it declared once, for inner purposes. 如果不映射该列,则出于内部目的,Hibernate会将其视为已声明一次。 If you declare it, that's twice, hence the error. 如果声明它,那是两次,因此是错误。

This is because sponsered columns in SP is already mapped by @DiscriminatorValue which should always equal to "true" . 这是因为@DiscriminatorValue已经映射了SP sponsered列,该值应始终等于“ true”。

If you map sponsered columns twice for update/insert , Hibernate will get confused as it does not know which values should it use for update /insert . 如果您两次将sponsered列映射为update / insert,则Hibernate会感到困惑,因为它不知道应将哪些值用于update / insert。 But after you change sponsered column to read-only mode (ie insertabl=false , updtable=false ) , hibernate knows what values should it use for update / insert as there is only single source of truth. 但是在将sponsered列更改为只读模式(即insertabl=falseupdtable=false )之后,hibernate知道应该使用哪些值进行更新/插入,因为只有唯一的事实来源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 实体映射中的重复列应映射为insert =“ false” update =“ false” - Repeated column in mapping for entity should be mapped with insert=“false” update=“false” MappingException:实体映射中的重复列:...列:dept_id(应映射为 insert="false" update="false") - MappingException: Repeated column in mapping for entity: ... column: dept_id (should be mapped with insert="false" update="false") JPA OneToMany 和 ManyToOne throw:实体列映射中的重复列(应映射为 insert=“false” update=“false”) - JPA OneToMany and ManyToOne throw: Repeated column in mapping for entity column (should be mapped with insert=“false” update=“false”) 实体映射中的重复列:entity.LaAssociateGridEntity 列:AssociateId(应使用 insert=“false” update=“false”进行映射) - Repeated column in mapping for entity: entity.LaAssociateGridEntity column: AssociateId (should be mapped with insert=“false” update=“false”) 例外:实体映射中的重复列:列:hash(应使用 insert=“false” update=“false”进行映射) - Exception: Repeated column in mapping for entity: column: hash (should be mapped with insert=“false” update=“false”) 实体映射中的重复列:BatchJobConfig列:BATCH_JOB_CONFIG_ID(应使用insert =“false”update =“false”映射) - Repeated column in mapping for entity: BatchJobConfig column: BATCH_JOB_CONFIG_ID (should be mapped with insert=“false” update=“false”) org.hibernate.MappingException:实体映射中的重复列:...列:add_by(应使用 insert=“false” update=“false”进行映射) - org.hibernate.MappingException: Repeated column in mapping for entity:…column: added_by (should be mapped with insert=“false” update=“false”) MappingException 实体映射中的重复列:models.Book 列:author_id(应使用 insert="false" update="false" 进行映射) - MappingException Repeated column in mapping for entity: models.Book column: author_id (should be mapped with insert="false" update="false") 无法建立Hibernate SessionFactory插入更新为false - Unable to build Hibernate SessionFactory insert update false 应该将数据源的自动提交设置为false吗? - Should autocommit of a datasource be set to false?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM