Webservice methods using EclipseLink and database entities I am wondering if this is a good and correct way to write the implementation of two web service methods (get/set methods).

The setPerson method can be called from different threads from a pool, so I think the best way is to make the method synchronized. Or is it possible to lock the table when editing to avoid the synchronization on Java?

@Override
public synchronized void setPerson(Person person) {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonLibPU");            
    EntityManager em = emf.createEntityManager(); 
    if(!em.getTransaction().isActive()) {
       em.getTransaction().begin();
    }
    try {
         em.merge(person);
         em.getTransaction().commit();  
         emf.getCache().evict(Person.class);                    
    } catch (Exception ex) {
         if(em.getTransaction().isActive())
            em.getTransaction().rollback();
    } finally {
        em.close();
    }
}


And here follows the getPerson method. I didn't make it synchronized since it reads from the JPA cache. 

@Override
public Person getPerson(int personId) {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("PersonLibPU");
    EntityManager em = emf.createEntityManager();
    try {           
        return (Person)em.getReference(Person.class, personId);
    } catch (javax.persistence.EntityNotFoundException ex) {
        return new Person(); // return empty person
    } finally {
        em.close();
    }
}
Just a few notes:

if(!em.getTransaction().isActive()) {
   em.getTransaction().begin();
}
try {
     em.merge(person);
     em.getTransaction().commit();  
     emf.getCache().evict(Person.class);
} catch (Exception ex) {
     if(em.getTransaction().isActive())
        em.getTransaction().rollback();
} finally {
    em.close();
}


I'd create a local variable for em.getTransaction() here and move the isActive check inside the try block. 

try {
    EntityTransaction transaction = em.getTransaction();
    try {
        if (!transaction.isActive()) {
            transaction.begin();
        }
        em.merge(person);
        transaction.commit();  
        emf.getCache().evict(Person.class);
    } finally {
        if (transaction.isActive()) {
            em.transaction.rollback();
        }
    }
} finally {
    em.close();
}


It closes the EntityManager in every code path as well as the transaction.

I've removed the exception catching. If you catch it consider at least logging it.

Evicting the whole Person cache every time you save a Person entity does not seem a good idea for performance.

Please note that if something call this method with an active transaction (I'm not sure if it's possible at all) it will returns with a committed or rollbacked, but not active transaction.