1

Currently, I am using Spring 4.0.6 with Postgresql 9.5. I am calling one serviceClass1 to another serviceClass2 and getting an exception for a transaction as following:

serviceClass1.class

`@Transactional(readOnly = false, propagation = Propagation.REQUIRED,rollbackFor= { Throwable.class })
public Map<String, Object> storeUsersList(Map<String, Object> mapOfParams) throws Exception {
    Map<String, Object> returnMap = new HashMap<String, Object>();
if (userListToStore != null && !userListToStore.isEmpty()) {                
integrationService.manangePassCodes(org,userListToStore.size());
                for (Users singleUser : userListToStore) {
                    try {
                        getEm().update(singleUser);`

serviceClass2.class

@Override
@Transactional(readOnly=false,propagation=Propagation.REQUIRED
     ,rollbackFor{Throwable.class})
public void manangePassCodes(Organizations org,int userToRegisterCount)throws Exception{
//some Logic

here I am getting Exception at this place - getEm().update(singleUser);

Exception SQL state [25P02]; error code [0]; could not extract ResultSet

I have just read about this error about Postgres transaction but not able to get what should I use for Hibernate.

2 Answers 2

1

Not 100% sure if that is the case but in your storeUsersList method, you seem to be reusing already existing User collection which is stored in an instance variable userListToStore.

This collection of users is not initialized from inside of the transaction so the entities are most likely to be detached, as you are using container managed transactions.

In my opinion you should merge each of the entities before you perform the update, so that the persistence context is aware of them:

for (Users singleUser : userListToStore) {
      try {
        getEm().merge(singleUser);
        getEm().update(singleUser);
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but i have solved my problem by inspecting more and reading about this error message and I concluded that saving error is not at the getEm().update(singleUser);
sorry for existing comment. thanks but I have solved my problem by inspecting more and reading about this error message above. and it means that previous transaction is aborted next one can not proceed that saving error is not at the getEm().update(singleUser); whereas it was at integrationService.manangePassCodes(org,userListToStore.size()); piece of code Reference Link 1 - postgresql.org/message-id/[email protected] Reference Link 2 - postgresql.org/docs/9.4/static/errcodes-appendix.html
1

Thanks for the Speedy help and I have got my problem solved by inspecting more and reading about this error message above.I was calling many transactions from a single transaction and it means in my case that due to previous transaction error next is aborted because it had the write lock on the DB. and your current transaction will not be saved until you sort out previous one. Previous Transaction which had silly mistake getEm().update(singleUser); Current Transaction which has nothing wrong integrationService.manangePassCodes(org,userListToStore.size‌()); piece of code Since both belong to different services but and I have annotated with @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = { Throwable.class }) propagation = Propagation.REQUIRED means that it will Support a current transaction, create a new one if none exists. So it gave me Error 25P02 - transaction aborted.

Reference Link 1 - postgresql.org/message-id/[email protected]

Reference Link 2 - postgresql.org/docs/9.4/static/errcodes-appendix.htm

Reference Link 3 - https://www.postgresql.org/message-id/8829.1173816732%40sss.pgh.pa.us

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.