• 由异常:Repeated column in mapping for entity/should be mapped with insert="false" update="false 引发对jpa关联的思考


    由异常:Repeated column in mapping for entity/should be mapped with insert="false" update="false 引发对jpa关联的思考

    首先说一下以上问题的解决方法

    //主键列 显示指定只读 --这块是解决该文的代码
    @Column(name = "xxx", insertable = false, updatable = false)

    @OneToMany(fetch = FetchType.LAZY)
    //关联异常时忽略异常
    @NotFound(action = NotFoundAction.IGNORE)
    //关联,显性指定关联字段
    @JoinColumns({@JoinColumn(name = "xxx", referencedColumnName = "xxx_ID", insertable = false, updatable = false) })
    List<TargetPersonModel> xxxs;

    对于该问题的思考

    1:首先解读一下column中insert 和 update的作用

     /**
         * (Optional) Whether the column is included in SQL INSERT 
         * statements generated by the persistence provider.
         */
        boolean insertable() default true;
    是否这一列别包含在持久化插入sql中是可以选择的

        /**
         * (Optional) Whether the column is included in SQL UPDATE 
         * statements generated by the persistence provider.
         */
        boolean updatable() default true;
    是否这一列被包含在持久化更新sql中是可以选择的

    2:这段代码对应的sql在数据库中无问题,但是代码关联确保这个错误

    sql:普通的左连接,这里就不贴啦,
    问题可能的原因:在关联过程中进行啦 插入或者更新操作

    解答上面的问题:已经显示指定啦insertable 和 updateable在joincolumns中 为什么还么报错?还要在字段上指定insertupdate

    针对该问题(已经显示指定啦insertable 和 updateable 为什么还么报错)回答:因为这俩个属性只是针对外键,即name字段,

    针对该问题(还要在字段上指定insertupdate?):而我在column中指定insertupdate是在referencecolumnname上。
  • 相关阅读:
    C# macro function via #define __FILE__ __LINE__ ___FUNCTION__ __DATE__ __TIME__
    3
    2月23号
    3月26
    impala故障
    2月3号日更
    HDFS某个节点的磁盘满了
    3月2
    mq集群
    3月3
  • 原文地址:https://www.cnblogs.com/xiaoshahai/p/12060199.html
Copyright © 2020-2023  润新知