spring boot application: jpa query returning old data

We have created a spring boot project using 1.3.5 version. Our application interacts with Mysql database. We have created a set of jpa-repositories in which we are using findAll, findOne and other custom queries methods.

We are facing a issue which is occurring randomly . Following are the steps to reproduce it:

  1. Fire a read query on db using spring-boot application.

  2. Now Manually change the data in Mysql using mysql-console of the records which were returned by above read query.

  3. Again fire the same read query using application.

After step 3 , we should have received the modified results of step 2, but what we got was the data before modification.

Now if we again fire the read query using application, It gives us correct values.

This issue occurs randomly. We are not using any kind of cache in our application.

While debugging I found out that jpa-repository code is infact calling mysql and it also fetches the latest result ,but when this call return back to our application service , surprisingly the return value has the old data.

Please help us identify the possible cause of it.

JPA/Datasource config:

  • spring.datasource.driverClassName=com.mysql.jdbc.Driver
  • spring.datasource.url=jdbc:mysql://localhost:3306/dbname?autoReconnect=true
  • spring.datasource.username=root
  • spring.datasource.password=xxx
  • spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
  • spring.datasource.max-wait=15000
  • spring.datasource.max-active=100
  • spring.datasource.max-idle=20
  • spring.datasource.test-on-borrow=true
  • spring.datasource.remove-abandoned=true
  • spring.datasource.remove-abandoned-timeout=300
  • spring.datasource.default-auto-commit=false
  • spring.datasource.validation-query=SELECT 1
  • spring.datasource.validation-interval=30000
  • hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
  • hibernate.show_sql=false
  • hibernate.hbm2ddl.auto=update

Service Method:

     @Override
    @Transactional
    public List<Event> getAllEvent() {
        return  eventRepository.findAll();
    }

JPARepository:

public interface EventRepository extends JpaRepository<Event, Long> {
    List<Event> findAll();
}

@Cacheable(false)

example:

@Entity
@Table(name="table_name")
@Cacheable(false)
public class EntityName {
    // ...
}

This might be because of some "DIRTY READS". Faced a similar issue, Try using Transactional Locks especially "Repeatable reads" which could probably avoid this problem. Correct me if I'm wrong.