whats up guys......sorry but I could not find anot...
# spring
a
whats up guys......sorry but I could not find another place to ask it...have been googling this issue for a while, probable using wrong key words. I using kotling with springboot in my backend app, which is just perfect, but there is one thing that I cant find a answer on the web, if some of you can help... So, in my UserServiceImpl.kt I have a save method that is using save from CrudRepository; My user table has a constraint for emails but even though I have a try catch on the save method it does not catch the exception
l
it is a typical problem and it is not related to kotlin. when you save entity with repository - you are just mark it for save in session. when you leave the save method, which is marked as transactional (by description of stacktrace), transaction starts to commit and session begin to flush data, after that hibernate start to insert data
a
Thanks @lex is there anything I can do?
l
try
JpaRepository.saveAndFlush(S)
or the other way (and right way) - check if the email is unique manually, constraint violation catching is bad practice and a lot of implicit, that is not good
@ander.dev
a
Thanks a lot @lex