Inherit property from parent class and add attribute to the inherited annotation

216 Views Asked by At

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?

0

There are 0 best solutions below