Jitendra Yadav
Jitendra Yadav

Reputation: 150

EntityManager merge function setting non-set values of the obect to null

em.merge() updating uninitialized properties of the entity to null..

@PersistenceContext
public EntityManager em;

    em.merge(invoice);

in my database it is updating all the values which were set in invoice object, as well as it is updating others to null as in invoice object those values were null.

what is the alternative of it so that i will update the object set values only.

Upvotes: 0

Views: 3084

Answers (1)

alambrache
alambrache

Reputation: 108

Merge works by first selecting from your DB the entity u are going to merge (in this case invoice) and will check every field for changes. If they are now null they will be set to null.

One way to fix this is to either pass around the full entity or manualy select and set the only the fields u want modified.

Upvotes: 1

Related Questions