The JPA delete and deleteById methods are not working, but the custom delete query and deleteAllByIdInBatch function as expected. Please review the code below.
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
@Entity
@Table(name = "foo")
public class Foo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Long Id;
@OneToMany(mappedBy = "foo", fetch = FetchType.EAGER, targetEntity = Boo.class)
private Set<Boo> boo;
Another entity
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
@Entity
@Table(name = "Boo")
public class Boo {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "boo_id")
private Long Id;
@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.PERSIST)
@JoinColumn(name = "foo_id")
private Foo foo;
Service method implementation
Override
public void remove(FooVO fooVo) {
Foo foo= fooRepository.findById(fooVo.getId());
foo.getBoo().forEach(boo-> {
booRepository.delete(boo);
})
Repository
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import com.ceva.spring.model.Boo;
@Repository
public interface BooRepository extends JpaRepository<Boo, Long> {}
After upgrading from Spring Boot version 2.5.12 to 3.2.5 and from JDK 11 to JDK 21, the Spring JPA delete method has stopped working, and no delete query is being executed when the delete method is called.