last day (15 days later) » 

5:47 PM
0
Q: Spring Data Repository does not delete ManyToOne Entity

NitekI'm am currently trying to use a Spring Data repository to delete some of my entities. The delete call works without any exceptions/error messages, but the entity is not deleted afterwards. Those are my entities: public class Board implements Serializable { @Id @GeneratedValue(generato...

 
Did you try postRepository.delete(50L); with a long?
 
Well the actual code is more like public void delete(Post post) { postRepo.delete(post.getId()); } so, yes.
 
It's weird because few days ago I developed almost the same without issues. Maybe you can have a look in the spring logs by adding a logger and set spring to trace level.
 
Do you have different Options in one of the OneToMany/ManyToOne or JoinColumn annotations?
 
Lazy loading, no cascade type defined and no orphanRemoval defined. I suppose you annotated both classes with @entity? Does save and load work?
updatable = false ... Not sure if this is causing trouble. Did you try yo set this to true?
 
5:47 PM
Yes, I did. When I remove the post from the posts list in the board and save the board, then everything works fine, but I'd like to be able to delete a post directly ...
 
I understand. That should work
 
updateable = true also doesn't work
 
Did you flush after you deleted
Or was the board object still in the persistence context with the post?
 
the Service is @Transactional
works for all other operations (including update)
 
Very strange. I dont see anything wrong in your entities
Just an idea, maybe make it a JpaRepository in stead of a crudRepositiry
I don't know why... Its still Spring ;)
 
5:58 PM
Same thing
just doesn't make any sense ...
(well at least not until afterwards)
 

last day (15 days later) »