由异常: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上。
posted @   小傻孩丶儿  阅读(1362)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示