Update object to another using Panache JPA

1.8k views Asked by At

I'm working with PanacheRepositories in Quarkus. Currently I want to realize the function update(X x). Basically what I want is the function to do is check if an entity y exists having id==x.id exists and update it to x, however I can't figure out if this is possible without having to deep copy every attribute from x into y. I don't want that, because the object is huge.

Is there any way to do something like

MyEntity y = repository.findById(x.id);
if(y != null){
  y = x;
  repository.persist(y)
}

without detaching the entity?

1

There are 1 answers

0
Urr4 On BEST ANSWER

I didn't realize that PanacheRepository is just an overlay of EntityManager, which has the functionality I'm looking for. So I could just inject the EntityManager and use merge(x) which did exactly what I wanted