Override Cascade

Hello,
I would like to know if it is possible to redefine in a child class the type of cascade defined for a variable declared in a parent class?

Because in a case for a child class I want to recover everything and in another. Functionally it seems consistent to me to have this case.

public class  Acteur {
  @OneToMany(mappedBy = "acteur", cascade = ALL)
  private Set<Role> roles = new HashSet<>();
}

public class AgenceBancaire extends Acteur {
 // Override Cascade for roles to load nothing?
}

Thanks a lot.

No, that isn’t possible.

Thank you ! Suddenly we will manage differently.

Just for my information, is it because it’s not implemented or because it’s technically not feasible or not desired?

The association is defined on a certain entity type, i.e. your base type Acteur so that’s the level where the cascading configuration lives. I think it’s not impossible to implement, but introduces quite some complexity in the current design as we’d have to know the concrete entity type in quite a few places to implement this properly.

How about you make Acteur abstract and introduce a RegularActeur which defines the roles with cascade ALL and in AgenceBancaire you define the roles again with a different cascade configuration?

In fact Acteur is already abstract, it is because he has several child classes.

I did not understand the modeling that you propose with the RegularActor?

You just move/copy down the roles association to all subtypes, where you can then control the cascades per subtype.

Ah OK. For the moment it seems complicated to me to modify the model.

For this particular case, I can get out of it by giving the cascade characteristics to our in-house framework.

For the explanation, to migrate our old management application to hibernate, and perform the migration over the long term, I use the information, the metadata of the hibernate annotations to transmit them to our relational mapping system which will generate DAO classes from this information.

And in a second time, we will switch to full hibernate.

Thank you anyway.

Well, you can omit the cascading configuration or use a conservative configuration and “implement” the additional cascading requirements you have for certain types yourself by issuing DML DELETE/UPDATE statements or calling EntityManager#remove().