We are using hibernate orm. Please refer the version in the attached snapshot. In the procedure we were doing the below on the single row. 1. SELECT 2. UPDATE 3. SELECT
This is to get old and updated new entity to our backend api server. So we were expecting two result set from the stored procedure. One result set with before update and another with after update. This is working fine in MySqlWorkBench, where we got two result grid (OLD ROW + NEW/UPDATED ROW). But when we try the same in Hibernate with the below code, we are getting the same old record twice, both result set is having the same old record before update.
The below is the code.
private EntityManagerFactory entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory"); public void callStoredProcedure() { try { EntityManager entityManager = entityManagerFactory.createEntityManager(); StoredProcedureQuery query = entityManager.createStoredProcedureQuery("new_procedure", Credit.class); query.registerStoredProcedureParameter("id", String.class, ParameterMode.IN); query.registerStoredProcedureParameter("amount", Double.class, ParameterMode.IN); query.registerStoredProcedureParameter("success", Integer.class, ParameterMode.OUT); query.setParameter("id", "b707f94d-6286-4cd3-a035-c6a99ead92bc"); query.setParameter("amount", 10.0); query.execute(); List<Credit> credit = query.getResultList(); System.out.println("OldCredit " + credit); if (query.hasMoreResults()) { List<Credit> newCredit = query.getResultList(); System.out.println("NewCredit " + newCredit); } System.out.println("get update " + query.getOutputParameterValue("success")); } catch (Exception e) { e.printStackTrace(); } }
The problem is only when the both the result set has the same select record, means 1. SELECT * FROM table WHERE id = 'idOne' 2. UPDATE table SET column_1 = 'value' WHERE id = 'idOne' 3. SELECT * FROM table WHERE id = 'idOne'
But it is not reproducible when the below two different records are returned from the stored procedure. 1. SELECT * FROM table WHERE id = 'idOne' 3. SELECT * FROM table WHERE id = 'idTwo'
Could you please help me? |
|