I have a group members table, which is tied to a users table in a one to one relationship, when I try to delete a record from the group members table, Nothing happens.

My Groups Table

public class Groups implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotBlank
    @Column(unique = true)
    private String groupName;

    @OneToMany(fetch = FetchType.LAZY, orphanRemoval = false, mappedBy = "group")
    private List<GroupMembers> members;
}

Group Members Table

public class GroupMembers implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "group_id", nullable = false)
    private Groups group;

    @OneToOne
    @JoinColumn(name = "user_id", nullable = false)
    private User user;
}

Users Table

public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String firstName;

    @OneToOne(fetch = FetchType.LAZY, mappedBy = "commutersInfo", cascade = CascadeType.ALL, orphanRemoval = true)
    private GroupMembers groupMembers;
}

When I try the following to delete a record nothing happens

groupsMembersRepository.delete(groupsMembersRepository.findByUserEmail(email));

No errors, No debug info in the console, it just doesn't delete the record from database

1 Answers

0
alex davies On

For Some reason JPA is not running my delete commands, when I do this spring.jpa.show-sql=true, I see all select queries and JPA does not run my delete query, I do not know why but I would like some explanation.

Eventually I had to use this

@Modifying
    @Query(value = "DELETE FROM `group_members` WHERE `commuters_info_id` = ?1", nativeQuery = true)
    public void deleteByCommutersInfoEmail(long id);