Followng method serves 2 purpose (saves and updates). Problem when updating a record - multiple inserts occur. What could be the possible causes? Thanks
line: em.merge(aEntropy);
Code:@Stateless @Service("jpaEntropyService") @Repository @Transactional public class EntropyServiceImpl implements EntropyService { private Log log = LogFactory.getLog(EntropyServiceImpl.class); @PersistenceContext(type=PersistenceContextType.EXTENDED) private EntityManager em; ... @Transactional public Entropy save(Entropy aEntropy) { if(aEntropy.getEntropyId() == null){ //New Entropy log.info("Inserting new Entropy"); em.persist(aEntropy); }else{ //Update Entropy em.merge(aEntropy); //<--- here log.info("Updating Entropy Record"); } log.info("Entropy Saved with id: "+ aEntropy.getEntropyId()); return aEntropy; }


Reply With Quote
