为什么JPA会更新OrderColumn而不是在创建时对其进行设置? [英] Why does JPA update the OrderColumn instead of setting it on creation?

查看:75
本文介绍了为什么JPA会更新OrderColumn而不是在创建时对其进行设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的OrderColumn上的表中添加一个NOT NULL约束.使用约束运行我的代码时,出现约束违规错误.在没有约束的情况下运行,我看到该行首先插入时没有OrderColumn,然后在使用正确的OrderColumn之后立即进行更新.有这种行为的原因吗?

I want to add a NOT NULL constraint to my table on my OrderColumn. Running my code with the constraint I get a constraint violation error. Running without the constraint I see that the row is first inserted without the OrderColumn, and then updated immediately after with the correct OrderColumn. Is there a reason for this behavior?

我管理OrderColumn的实体:

My entity managing the OrderColumn:

@Entity
@Table(name="INSPECTION")
public class Inspection implements Serializable
{
    ...
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, orphanRemoval=true)
    @OrderColumn(name="LIST_INDEX", nullable=false)
    @JoinColumn(name="INSPECTION_ID")
    private List<RecommendationInstance> recommendations;
    ...
}

此问题源自为什么是JPA在一个基本用例中忽略了@OrderColumn?在这里,我为什么没有插入OrderColumn感到困惑.可以在此处看到其他代码示例.

This question stemmed from Why is JPA ignoring my @OrderColumn in a basic use case? where I was confused as to why my OrderColumn wasn't getting inserted. Additional code samples can be seen there.

推荐答案

此处的问题是,RecommendationInstance实体是一个独立的实体,没有针对订单列的映射.Eclipselink旨在仅从实体本身创建插入.有一个功能请求,它具有eclipselink存储语句,并在处理其他映射时将其添加到它们中,但是我仍然不方便.

The issue here is that the RecommendationInstance entity is a separate and independent entity that does not have a mapping for the order column. Eclipselink is designed to create inserts only from the entity itself. There is a feature request to have eclipselink store statements and add to them as it processes other mappings, I still don't have it handy though.

这篇关于为什么JPA会更新OrderColumn而不是在创建时对其进行设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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