1

based on this article https://thorben-janssen.com/spring-data-jpa-save-saveandflush-and-saveall/ I understand that calling a save for a managed entity is waste or resources and not actually required, and I tried this in my local and it works as expected. e.g:


@Override
@Transactional
public UserEntity update(User user){
UserEntity e = userRepo.findById(user.getId());
e.setName("test");
return e;
}

without calling the save method the update query is called.

but when I call it from an inner method ,i.e


@Override
public UserEntity update(User user){
return performUpdate(user);
}

@Transactional
public UserEntity performUpdate(User user){
UserEntity e = userRepo.findById(user.getId());
e.setName("test");
return e;
}

Now for some reason the update query is not being called at all, can someone explain me why this is happening and how can I fix this?

Akash Jain
  • 684
  • 9
  • 23
  • 1
    Many Java annotations, including Transactional, require a proxy to be setup on the method. This requires that the method is called from another class. – John Williams Apr 15 '23 at 20:26

0 Answers0