2

I am using DAO class to persist/save/update the data in entity table.For this I iterate the list of objects and then get the the entity table(Task Queue) id from database if it exist then update its record in database.

I am using this code to update the record in database..

EDIT

public void saveobj(ObjectMetadata om){

         taskQueue = taskQueueDAO.getTaskQueueId(om.getId());
         taskQueue.setLob_compression_status("completed");
         taskQueue.setEnd_time(LocalDateTime.now());
         taskQueueDAO.saveOrUpdate(taskQueue);
         taskQueueDAO.getEm().flush();
         taskQueueDAO.getEm().clear();
         taskQueueDAO.close();
}

public static someMethod( ){
      for (ObjectMetadata om : oms) {
         otherclass.saveobj(om);
      }
}

By this code the objects are not update one by one in database. when the for loop ends completely then all entries are update at one time in database.

I want to update the entry one by one when saveorupdate function is call.What can I do for this?

parita porwal
  • 662
  • 1
  • 10
  • 32
  • Are you using transactions? If you are using transactions, then you'll only see the results in a database browser once the transaction commits. – Erwin Bolwidt Aug 17 '16 at 12:44
  • No I am not using transaction..@ErwinBolwidt – parita porwal Aug 17 '16 at 12:55
  • Have you tried adding: taskQueueDAO.getEm().getTransaction().commit(); – bilgec Aug 17 '16 at 14:23
  • In spring, remove the entityManager.getTransaction().commit(); statement as now all the transaction management will be handled by spring, if you leave the statement as it is then you will get the same error again. as suggested in link - [link](http://stackoverflow.com/questions/17860696/not-allowed-to-create-transaction-on-shared-entitymanager-use-spring-transacti). I got java.lang.IllegalStateException: Not allowed to create transaction on shared EntityManager - use Spring transactions or EJB CMT instead exception. – parita porwal Aug 24 '16 at 07:52

0 Answers0