Reddy Reddy - 8 months ago 33
Java Question

Hibernate One to Many Mapping is trying to update mapping column to null

I am using below mapping

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

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

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

//getters and setters

public class TestDetails implements Serializable {

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

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

When I update/insert the data, it's trying to update the
to null

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

Any help is much appreciated.

Updating/Inserting using 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" />


You need to fetch values of TestDetails entity eagerly.

Just modify in your annotation with,

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

Hope this will work.