I have read that hibernate 4.0 until 4.1.3 had the issue of not freeing/deallocate (I am not proficient in database management) the OracleSql cursors after closing the connection or after executing the statement.
Although I have increased the maximum cursors on the DataBase, it was just a matter of time until the maximum number of cursors was reached yet again. I am pretty sure this is where the problem resides because the build fails and not when running a particular test or test class.
Is it still a known problem in Hibernate 5? And if yes, how do I manually free the cursors?
I am using, for sake o completeness:
- Hibernate-core-5.0.11 - from what I've read this should handle the
cursors
- Hibernate-entitymanager-5.0.11
- Hibernate-jpa-2.1-api-1.0.0
- Oracle database 11.2.0.1
The Repository that (I suppose) causes the problems:
package org.mypackage.status;
import java.util.stream.Stream;
import org.mypackage.entity.status.Status;
import org.mypackage.entity.status.StatusContract;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
public interface StatusContractRepository extends CrudRepository<StatusContract, Long>{
@Query("select cs from StatusContract cs")
Stream<StatusContract> streamAll();
@Query("select cs from StatusContract cs where cs.name=?1")
StatusContract findOneByName(final Status name);
}
The Service function that I am testing and which uses the aforementioned repository ):
@Service
public class StatusService {
private final StatusContractRepository statusContractRepository;
private final ContractRepository contractRepository;
public StatusService(final StatusContractRepository statusContractRepository, final ContractRepository contractRepository) {
this.statusContractRepository = Objects.requireNonNull(statusContractRepository, "statusContractRepository must not be null.");
this.contractRepository = Objects.requireNonNull(contractRepository, "contractRepository must not be null.");
}
public String setContractStatus(final DocComm lastDocComm) {
Contract contract = lastDocComm.getContract();
if (lastDocComm.getAnswer() != null) {
switch (lastDocComm.getAnswer().getDocumentType().getCode()) {
case DocumentType.A_REQ_CLARIFY:
contract.setStatus(statusContractRepository.findOneByName(Status.CLAR_RECEIVED));
break;
case DocumentType.A_REQ_DOC_ADDITIONAL:
contract.setStatus(statusContractRepository.findOneByName(Status.CLAR_RECEIVED));
break;
// there are more cases; they have the same behavior
default:
break;
}
} else if (lastDocComm.getRequest() != null) {
switch (lastDocComm.getRequest().getDocumentType().getCode()) {
case DocumentType.REQ_TERMS:
contract.setStatus(statusContractRepository.findOneByName(Status.REQ_TERM));
break;
case DocumentType.REQ_MODIFY:
contract.setStatus(statusContractRepository.findOneByName(Status.REQ_MODIFY));
break;
// there are more cases; they have the same behavior
// the first few calls are alright, or when I run specifically one call
// the problem occurs at build when it calls all the functions
default:
break;
}
}
contractRepository.save(contract);
return contract.getStatus().getFullName();
}
}
The Log from NetBeans:
testChangeStatus_1
[WARN ] 2017-04-18 09:07:13 [o.h.e.j.s.SqlExceptionHelper:127]- SQL Error: 604, SQLState: 60000
2017-04-18 09:07:13 [o.h.e.j.s.SqlExceptionHelper:129]- ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded
[INFO ] 2017-04-18 09:07:13 [o.h.e.i.DefaultLoadEventListener:129]- HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: could not extract ResultSet
[INFO ] 2017-04-18 09:07:13 [o.h.e.i.DefaultLoadEventListener:129]- HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: could not extract ResultSet
[INFO ] 2017-04-18 09:07:13 [o.h.e.i.DefaultLoadEventListener:129]- HHH000327: Error performing load command : org.hibernate.exception.GenericJDBCException: could not extract ResultSet
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:63]- DECLARE return_code number; BEGIN SP_STERGE_INREGISTRARE ('COMMUNICATION_DOC',6515, 'null', to_date('2017-04-18','YYYY-mm-dd'), 'FO', return_code); END;
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:67]- SQL_CALL_RESULT: 1
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:63]- DECLARE return_code number; BEGIN SP_STERGE_INREGISTRARE ('CONTRACT',9824, 'null', to_date('2017-04-18','YYYY-mm-dd'), 'FO', return_code); END;
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:67]- SQL_CALL_RESULT: 1
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:63]- DECLARE return_code number; BEGIN SP_STERGE_INREGISTRARE ('DOCUMENT',21551, 'null', to_date('2017-04-18','YYYY-mm-dd'), 'FO', return_code); END;
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:67]- SQL_CALL_RESULT: 1
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:63]- DECLARE return_code number; BEGIN SP_STERGE_INREGISTRARE ('DOCUMENT',21552, 'null', to_date('2017-04-18','YYYY-mm-dd'), 'FO', return_code); END;
[INFO ] 2017-04-18 09:07:14 [o.m.a.AbstractEntityListener:67]- SQL_CALL_RESULT: 1
testChangeStatus_2
[WARN ] 2017-04-18 09:07:14 [o.h.e.j.s.SqlExceptionHelper:127]- SQL Error: 604, SQLState: 60000
2017-04-18 09:07:14 [o.h.e.j.s.SqlExceptionHelper:129]- ORA-00604: error occurred at recursive SQL level 1
ORA-01000: maximum open cursors exceeded
ORA-01000: maximum open cursors exceeded
...
This goes on for a number of other test functions.
If there's any need for further details, I will hastily provide them.