JPA OneToMany Cacade.ALL creating two entries for the parent?

This is because you mapped the same bidirectional association twice: once in Bill (with JoinColumn(name = "bill_id", nullable = true) on the list of items), and once in BillLineitem (with JoinColumn(name = "bill_id", nullable = false) on the bill field) The OneToMany side should just be marked as the inverse association of the ManyToOne side, and the list of items should just be annotated with OneToMany(fetch = FetchType. LAZY, cascade = CascadeType. ALL, mappedBy = "bill") Remove the JoinColumn annotation.

This is because you mapped the same bidirectional association twice: once in Bill (with @JoinColumn(name = "bill_id", nullable = true) on the list of items), and once in BillLineitem (with @JoinColumn(name = "bill_id", nullable = false) on the bill field). The OneToMany side should just be marked as the inverse association of the ManyToOne side, and the list of items should just be annotated with @OneToMany(fetch = FetchType. LAZY, cascade = CascadeType.

ALL, mappedBy = "bill"). Remove the @JoinColumn annotation.

Sorry for the late response. Thanks a lot. This works.

Will do the same everywhere. Also, when I am doing a1. Add(b1) and then a1 = aDao.

Save(a1), the b1. Id is still 0 but its 1 in the same b1 within a1. Since both b1 and the one inside a1 point to the same instance, why isnt the id of b1 not updated?

– Abhilash Aug 29 at 5:43 You should ask another question for this. Merge doesn't make an entity persistent. It returns a persistent copy of the passed entity.

After a merge, you thus have instances: the one passed as argument, which is left transient, and the one returned by the merge method, wich is persistent and attached. – JB Nizet Aug 29 at 7:21.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions