mardi 14 avril 2015

Spring Data CrudRepository and Transactions

I'm trying to implement transactions on a CrudRepository Interface. I'm a beginner with this and my current problem is that when receiving a lot of requests from different clients, I'm sometimes getting a duplicate. To avoid that I wanted to use SQL Transactions and their implementation with Spring but I'm unable to get it working.


Here is how I've tried to do it :



@Repository
@EnableTransactionManagement
@Transactional
public interface ApplicationPackageDao extends CrudRepository<ApplicationPackage, Long> {

/**
* Find if a record exists for this package name ,
* @param packageName
* @return
*/
@Transactional
ApplicationPackage findByPackageName(String packageName);

}


However it doesn't seem to work. I tried to add the @Transactionnal annotations earlier in the Java methods I'm calling but I can't get it working either.


How am I supposed to work with transactions on CrudRepository ? Or am I using completely the wrong thing?


Aucun commentaire:

Enregistrer un commentaire