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?
}
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?
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.
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().