use of jakarta.persistence.CascadeType in project hibernate-orm by hibernate.
the class JPAXMLOverriddenAnnotationReader method overridesDefaultCascadePersist.
private Annotation overridesDefaultCascadePersist(Annotation annotation, XMLContext.Default defaults) {
if (Boolean.TRUE.equals(defaults.getCascadePersist())) {
final Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType == ManyToOne.class) {
ManyToOne manyToOne = (ManyToOne) annotation;
List<CascadeType> cascades = new ArrayList<>(Arrays.asList(manyToOne.cascade()));
if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
cascades.add(CascadeType.PERSIST);
} else {
return annotation;
}
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
ad.setValue("targetEntity", manyToOne.targetEntity());
ad.setValue("fetch", manyToOne.fetch());
ad.setValue("optional", manyToOne.optional());
return AnnotationFactory.create(ad);
} else if (annotationType == OneToOne.class) {
OneToOne oneToOne = (OneToOne) annotation;
List<CascadeType> cascades = new ArrayList<>(Arrays.asList(oneToOne.cascade()));
if (!cascades.contains(CascadeType.ALL) && !cascades.contains(CascadeType.PERSIST)) {
cascades.add(CascadeType.PERSIST);
} else {
return annotation;
}
AnnotationDescriptor ad = new AnnotationDescriptor(annotationType);
ad.setValue("cascade", cascades.toArray(new CascadeType[] {}));
ad.setValue("targetEntity", oneToOne.targetEntity());
ad.setValue("fetch", oneToOne.fetch());
ad.setValue("optional", oneToOne.optional());
ad.setValue("mappedBy", oneToOne.mappedBy());
ad.setValue("orphanRemoval", oneToOne.orphanRemoval());
return AnnotationFactory.create(ad);
}
}
return annotation;
}
Aggregations