1

I have 2 classes, class A with the follwing relationship:

@OneToMany(mappedBy = "aaa", cascade = CascadeType.ALL, orphanRemoval = true)
private List<B> bbb = new ArrayList<B>();

and class B:

@ManyToOne
@JoinColumn(name = "aaa", nullable = false)
private A aaa;

However when I try to delete an entity of class B nothing happens. I'm not getting any errors and no SQL-Statements get executed.

B b = em.find(B.class, id)
em.remove(b);

Anything I am obviously doing wrong here?

  • Nothing happens as in "it is not deleted from B table" or as in "the relation to A is not followed"? – NiVeR Sep 27 '18 at 10:46
  • Nothing happens as in "it is not deleted from B table". Table A doesnt hold any information about B. –  Sep 27 '18 at 10:49
  • 1
    Are you in a transactional context? Do you commit the delete? – NiVeR Sep 27 '18 at 10:49
  • Im beginning a transaction, removing b, comitting and closing the entity manager, nothing else –  Sep 27 '18 at 10:50
  • do you get any exceptions? – Simon Martinelli Sep 27 '18 at 11:07
  • Absolutely no exceptions. If I try to delete "a" everything works fine. The cascading works and both get deleted from the database. –  Sep 27 '18 at 11:25

1 Answers1

-1

You can use it,

@OneToMany(mappedBy = "aaa",cascade = CascadeType.PERSIST, fetch = FetchType.EAGER, orphanRemoval=true)
private List<B> bbbb;

and here you create Setter and Getter methods of List<B> in bean class.

@ManyToOne(fetch=FetchType.EAGER,optional=false)
    @JoinColumn(name="aaa")
    private A aaa;
Sushil Kumar
  • 84
  • 1
  • 10