We are using spring data jpa (spring boot 1.5) and queryDSL to interact with Mysql DB. I am trying to **intercept all DB calls like insert and update** to do some operations like encryption/decryption.
I tried to implement JPA callbacks like preUpdate but none of them are being called when a DB query implemented using queryDSL.
On the other hand, JPA callbacks works when I use CrudRepository methods like save.
@Entity
@Table(name = "APPLICATION")
public class Application implements Serializable {
@Id
@Column(name = "ID", unique = true)
private Long id;
@Column(name = "PAN", insertable = false)
private String pan;
@PreUpdate
void preUpdate() throws IOException, HttpException {
//logic to encrypt before update is called
}
}
QueryDSL call
@Autowired
private JPAQueryFactory queryFactory;
@Transactional
@Override
public void updatePanById(String pan, Long id) {
QApplication application = QApplication.application;
queryFactory.update(application)
.set(application.pan, pan)
.where(loan.id.eq(id))
.execute();
}
JPA code
Application application = applicationRepository.findById(id);
application.setPan("ABC");
applicationRepository.save(application);
In our application we are using QueryDSL, native queries and CrudRepository methods and want to intercept all DB calls at centralised place. Is this achievable in any way ?