Home » Support » Forum » persists and update together ?

persists and update together ?

#1

hello on mysql i've seen;

 

INSERT INTO table (a,b,c) VALUES (1,2,3),(4,5,6) ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);

 

This query , inserts data or updates if its already available and this will reduce finding same object again.

On jpa :

    User obj2 = ...;

    User usr2 = entityManager.find(User.class,user.getGid());
    if(usr2 != null) {
        entityManager.refresh(obj2);
    }
    else {
        entityManager.persist(obj2); 
    }

We need to first find the object available then update if its available, if not add new object to db.

 

This will make more cycle then on mysql on top.

 

Is there any shortcut persists object if its not available , if its available  just update the object.

Without calling find , can we do this ?

 

#2

Maybe merge instead of persist is what you are looking for.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Post Reply

To post a reply and/or subscribe to update notifications - please login