I'm using Spring JPA in Spring-boot project. I have a simple named query. The proc gets invoked every 10 seconds. Without the @Transactional annotated over my repository interface, the connection in the connection pool runs out. I get "Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:100; busy:100; idle:0; lastwait:30000]."
However, after I added @Transactional annotation, it works just fine. What is the relation between the annotation and the connections being released back to the pool? I thought Spring JPA would automatically release the connection after the method invocation is complete.
@Repository
@Transactional
public interface StoredProcedureRepository extends CrudRepository<StoredProcedureDO, Long> {
@Procedure(name = "invokeStoredProc")
void invokeStoredProc(@Param("id") Long id, @Param("date") java.sql.Date date);
}
@Entity
@NamedStoredProcedureQuery(name ="invokeStoredProc",
procedureName = "schema.storedProc",
parameters = {
@StoredProcedureParameter(mode = ParameterMode.IN, name = "id", type = Long.class),
@StoredProcedureParameter(mode = ParameterMode.IN, name = "date", type = java.sql.Date.class)})
public class StoredProcedureDO implements Serializable {