Using hibernate 5.2.2 and DB2 LUW 10.5.
Inside of a transactional persistence context, there is an entity that is loaded via query and never changed, but then hibernate performs an UPDATE for this entity. This is a simple transaction involving two classes A and B. Class A is the class of the instance that gets the unwanted UPDATE. Class A has a generated ID strategy:
Code:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID")
private Integer id;
Class B has an association to A:
Code:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "A_ID")
private A myA;
But there is no reverse @OneToMany collection mapping in class A.
These are the specific steps:
1. Start the transaction
2. Call EntityManager.find(id) to load entity A1 of class A
3. Create new entity instance B1 of class B
4. Set B1.myA = A1
5. Call EntityManager.persist(B1)
6. Commit the transaction
Hibernate performs INSERT for B1, but also performs unwanted UPDATE for A1. Is there any way to prevent hibernate performing the UPDATE of A1?