gpt4 book ai didi

java - Hibernate 一对多映射正在尝试将映射列更新为空

转载 作者:搜寻专家 更新时间:2023-10-31 08:14:57 25 4
gpt4 key购买 nike

我正在使用下面的映射

@Entity
@Table(name = "test")
public class TestOrder implements Serializable {

@Id
@Column(name = "orderid", updatable = false)
protected Long orderId;

@OneToMany(cascade = {CascadeType.ALL})
@JoinColumn(name = "order_id_fk")
private List<TestDetails> details;

//getters and setters
}

@Entity
@Table(name="test_details")
public class TestDetails implements Serializable {

@Id
//Generator
@Column(name = "id", updatable = false, insertable = false)
protected Long id;

@Column(name="order_id_fk", updatable = false)
private Long orderId;
//getters and setters
}

当我更新/插入数据时,它试图将 order_id_fk 更新为 null

SQL [update test_details set order_id_fk'='null where order_id_fk'='? and id'='?]; constraint [null];

非常感谢任何帮助。

使用 Spring Integration 更新/插入

<int-jpa:updating-outbound-gateway entity-class="com.aaaa.TestOrder" entity-manager-factory="myEntityManagerFactory" persist-mode="MERGE">
<int-jpa:transactional propagation="REQUIRED" transaction-manager="myTransactionManager" />
</int-jpa:updating-outbound-gateway>

最佳答案

您需要急切地获取 TestDetails 实体的值。

只需在注释中修改,

@OneToMany(fetch = FetchType.EAGER, mappedBy="testOrder", cascade=CascadeType.ALL)

希望这会奏效。

关于java - Hibernate 一对多映射正在尝试将映射列更新为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24487865/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com