Announcement Announcement Module
Collapse
No announcement yet.
entitymanager multiple insertion Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • entitymanager multiple insertion

    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;
    		
    	}
Working...
X