Domanda

Now I am using jpa with hibernate , when i was done getEntityManager.persist(objects) then i will ask for user confirmation like continue and rollback using user interface

private List<TempCustomers> tempCustomer =new ArrayList<TempCustomers>();

 @Begin(join = true)
    public String migrateData() {

    log.info("Mobee Migrate Customer Size  :"+doTempCustomers.size());




            for(DoTempCustomers tempCustomers:doTempCustomers){
            try {

                TempCustomers temp=new TempCustomers();
                BeanUtils.copyProperties(temp, tempCustomers);


                tempCustomer.add(temp);
                getEntityManager().persist(temp);

            }catch (Exception e) {
                // TODO: handle exception
                return "null";
            }

             }
            log.info("Size........."+tempCustomer.size());
            return "null";
    }

@Begin(join = true)
    public String updatedData(){
         log.info("Size of Customers :"+tempCustomer.size());
         log.info("Decision ..."+decision);

        try{    
       if(decision.equals("Continue")){
        for(TempCustomers tempCust:tempCustomer){

            TempCustomers temp=new TempCustomers();
            BeanUtils.copyProperties(temp, tempCust);   

            log.info("updated Sucessfully");

           getEntityManager().getTransaction().commit();

       }}else{
           getEntityManager().getTransaction().rollback();

        }
        }
        catch(Exception e){

        }
}

please help me how to do continue and rollback in jpa with hibernate when getEntityManager().persist() is done.

È stato utile?

Soluzione

To commit with JPA:

entityManager.getTransaction().commit();

To rollback with JPA:

entityManager.getTransaction().rollback();

Call either of these methods after your call to persist to perform the desired action. In your case entityManager would be replaced with the call to retrieve the entityManager, getEntityManager()

Reference: http://www.objectdb.com/java/jpa/persistence/store

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top