I have a spring 4 app where I\'m trying to delete an instance of an entity from my database. I have the following entity:
@Entity
public class Token impleme
One way is to use cascade = CascadeType.ALL
like this in your userAccount service:
@OneToMany(cascade = CascadeType.ALL)
private List tokens;
Then do something like the following (or similar logic)
@Transactional
public void deleteUserToken(Token token){
userAccount.getTokens().remove(token);
}
Notice the @Transactional
annotation. This will allow Spring (Hibernate) to know if you want to either persist, merge, or whatever it is you are doing in the method. AFAIK the example above should work as if you had no CascadeType set, and call JPARepository.delete(token)
.