Red*_*ddy 5 java spring annotations hibernate jpa
我正在使用下面的映射
@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
}
Run Code Online (Sandbox Code Playgroud)
当我更新/插入数据时,它正在尝试将数据更新order_id_fk
为null
SQL [update test_details set order_id_fk'='null where order_id_fk'='? and id'='?]; constraint [null];
Run Code Online (Sandbox Code Playgroud)
任何帮助深表感谢.
使用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>
Run Code Online (Sandbox Code Playgroud)
Har*_*til 11
您需要TestDetails
急切地获取实体的值.
只需在注释中修改,
@OneToMany(fetch = FetchType.EAGER, mappedBy="testOrder", cascade=CascadeType.ALL)
Run Code Online (Sandbox Code Playgroud)
希望这会奏效.
归档时间: |
|
查看次数: |
8453 次 |
最近记录: |