0

I have a derived class MyBusinessBody which extends a parent class BusinessBody.

One field in BusinessBody looks like:

public class BusinessBody{
  @OneToOne(fetch = FetchType.LAZY)
  private Trade trade;
  //setter and getter
  ... 
}

Now, I want to add another attribute, "cascade = CascadeType.ALL" to the annotation @OneToOne, but I don't want to do it inside BusinessBody, rather, I'd like it amended in the derived class MyBusinessBody.java, something like:

public class MyBusinessBody{
  @OneToOne(fetch = FetchType.LAZY,cascade = CascadeType.ALL)
  protected Trade trade; //NOTE: I changed the modifier from "private" to "protected", otherwise the IDE shows warning that this field is not used.
  //setter and getter
  ... 
}

Will this work?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
J.E.Y
  • 1,173
  • 2
  • 15
  • 37
  • Private access modifier is secure your data – Faheem azaz Bhanej Nov 17 '21 at 11:06
  • #ide_warning: it should be used in (public) g-/setter!?/ignore/deactivate it ;) #cascade: it depends: how you want to map (uni-/bi)?; and who should cascade whom? (but i think all (4?) cases should be possible) – xerx593 Nov 17 '21 at 11:33

0 Answers0