66
77import java .lang .annotation .Annotation ;
88import java .util .Comparator ;
9+ import java .util .EnumSet ;
910import java .util .HashMap ;
1011import java .util .List ;
1112import java .util .Locale ;
1718import org .hibernate .AssertionFailure ;
1819import org .hibernate .FetchMode ;
1920import org .hibernate .MappingException ;
20- import org .hibernate .annotations .Bag ;
21- import org .hibernate .annotations .Cache ;
22- import org .hibernate .annotations .CacheLayout ;
23- import org .hibernate .annotations .Cascade ;
24- import org .hibernate .annotations .Check ;
25- import org .hibernate .annotations .Checks ;
26- import org .hibernate .annotations .CollectionId ;
27- import org .hibernate .annotations .CollectionIdJavaType ;
28- import org .hibernate .annotations .CollectionIdJdbcType ;
29- import org .hibernate .annotations .CollectionIdJdbcTypeCode ;
30- import org .hibernate .annotations .CollectionType ;
31- import org .hibernate .annotations .Columns ;
32- import org .hibernate .annotations .CompositeType ;
33- import org .hibernate .annotations .Fetch ;
34- import org .hibernate .annotations .FetchProfileOverride ;
35- import org .hibernate .annotations .Filter ;
36- import org .hibernate .annotations .FilterJoinTable ;
37- import org .hibernate .annotations .Formula ;
38- import org .hibernate .annotations .HQLSelect ;
39- import org .hibernate .annotations .Immutable ;
40- import org .hibernate .annotations .LazyGroup ;
41- import org .hibernate .annotations .ListIndexBase ;
42- import org .hibernate .annotations .ListIndexJavaType ;
43- import org .hibernate .annotations .ListIndexJdbcType ;
44- import org .hibernate .annotations .ListIndexJdbcTypeCode ;
45- import org .hibernate .annotations .ManyToAny ;
46- import org .hibernate .annotations .MapKeyJavaType ;
47- import org .hibernate .annotations .MapKeyJdbcType ;
48- import org .hibernate .annotations .MapKeyJdbcTypeCode ;
49- import org .hibernate .annotations .MapKeyMutability ;
50- import org .hibernate .annotations .MapKeyType ;
51- import org .hibernate .annotations .NotFound ;
52- import org .hibernate .annotations .NotFoundAction ;
53- import org .hibernate .annotations .OnDelete ;
54- import org .hibernate .annotations .OnDeleteAction ;
55- import org .hibernate .annotations .OptimisticLock ;
56- import org .hibernate .annotations .Parameter ;
57- import org .hibernate .annotations .QueryCacheLayout ;
58- import org .hibernate .annotations .SQLDelete ;
59- import org .hibernate .annotations .SQLDeleteAll ;
60- import org .hibernate .annotations .SQLInsert ;
61- import org .hibernate .annotations .SQLJoinTableRestriction ;
62- import org .hibernate .annotations .SQLOrder ;
63- import org .hibernate .annotations .SQLRestriction ;
64- import org .hibernate .annotations .SQLSelect ;
65- import org .hibernate .annotations .SQLUpdate ;
66- import org .hibernate .annotations .SoftDelete ;
67- import org .hibernate .annotations .SortComparator ;
68- import org .hibernate .annotations .SortNatural ;
69- import org .hibernate .annotations .SqlFragmentAlias ;
70- import org .hibernate .annotations .Synchronize ;
21+ import org .hibernate .annotations .*;
7122import org .hibernate .boot .model .IdentifierGeneratorDefinition ;
7223import org .hibernate .boot .models .JpaAnnotations ;
7324import org .hibernate .boot .models .annotations .internal .JoinColumnJpaAnnotation ;
13990import static jakarta .persistence .ConstraintMode .NO_CONSTRAINT ;
14091import static jakarta .persistence .ConstraintMode .PROVIDER_DEFAULT ;
14192import static jakarta .persistence .FetchType .LAZY ;
93+ import static org .hibernate .annotations .CascadeType .DELETE_ORPHAN ;
14294import static org .hibernate .boot .model .internal .AnnotatedClassType .EMBEDDABLE ;
14395import static org .hibernate .boot .model .internal .AnnotatedClassType .NONE ;
14496import static org .hibernate .boot .model .internal .AnnotatedColumn .buildColumnFromAnnotation ;
14799import static org .hibernate .boot .model .internal .AnnotatedColumn .buildFormulaFromAnnotation ;
148100import static org .hibernate .boot .model .internal .AnnotatedJoinColumns .buildJoinColumnsWithDefaultColumnSuffix ;
149101import static org .hibernate .boot .model .internal .AnnotatedJoinColumns .buildJoinTableJoinColumns ;
102+ import static org .hibernate .boot .model .internal .BinderHelper .aggregateCascadeTypes ;
150103import static org .hibernate .boot .model .internal .BinderHelper .buildAnyValue ;
151104import static org .hibernate .boot .model .internal .BinderHelper .checkMappedByType ;
152105import static org .hibernate .boot .model .internal .BinderHelper .createSyntheticPropertyReference ;
153106import static org .hibernate .boot .model .internal .BinderHelper .extractFromPackage ;
154- import static org .hibernate .boot .model .internal .BinderHelper .getCascadeStrategy ;
155107import static org .hibernate .boot .model .internal .BinderHelper .getFetchMode ;
156108import static org .hibernate .boot .model .internal .BinderHelper .getPath ;
157109import static org .hibernate .boot .model .internal .BinderHelper .isDefault ;
@@ -202,7 +154,7 @@ public abstract class CollectionBinder {
202154 protected MemberDetails property ;
203155 private TypeDetails collectionElementType ;
204156 private TypeDetails targetEntity ;
205- private String cascadeStrategy ;
157+ private EnumSet < CascadeType > cascadeTypes ;
206158 private String cacheConcurrencyStrategy ;
207159 private String cacheRegionName ;
208160 private CacheLayout queryCacheLayout ;
@@ -514,12 +466,9 @@ private static String handleTargetEntity(
514466 collectionBinder .setFkJoinColumns ( joinColumns );
515467 mappedBy = nullIfEmpty ( oneToManyAnn .mappedBy () );
516468 collectionBinder .setTargetEntity ( oneToManyAnn .targetEntity () );
517- collectionBinder .setCascadeStrategy ( getCascadeStrategy (
518- oneToManyAnn .cascade (),
519- hibernateCascade ,
520- oneToManyAnn .orphanRemoval (),
521- context
522- ) );
469+ collectionBinder .setCascadeStrategy (
470+ aggregateCascadeTypes ( oneToManyAnn .cascade (), hibernateCascade ,
471+ oneToManyAnn .orphanRemoval (), context ) );
523472 collectionBinder .setOneToMany ( true );
524473 }
525474 else if ( elementCollectionAnn != null ) {
@@ -535,23 +484,15 @@ else if ( elementCollectionAnn != null ) {
535484 else if ( manyToManyAnn != null ) {
536485 mappedBy = nullIfEmpty ( manyToManyAnn .mappedBy () );
537486 collectionBinder .setTargetEntity ( manyToManyAnn .targetEntity () );
538- collectionBinder .setCascadeStrategy ( getCascadeStrategy (
539- manyToManyAnn .cascade (),
540- hibernateCascade ,
541- false ,
542- context
543- ) );
487+ collectionBinder .setCascadeStrategy (
488+ aggregateCascadeTypes ( manyToManyAnn .cascade (), hibernateCascade , false , context ) );
544489 collectionBinder .setOneToMany ( false );
545490 }
546491 else if ( property .hasDirectAnnotationUsage ( ManyToAny .class ) ) {
547492 mappedBy = null ;
548493 collectionBinder .setTargetEntity ( ClassDetails .VOID_CLASS_DETAILS );
549- collectionBinder .setCascadeStrategy ( getCascadeStrategy (
550- null ,
551- hibernateCascade ,
552- false ,
553- context
554- ) );
494+ collectionBinder .setCascadeStrategy (
495+ aggregateCascadeTypes ( null , hibernateCascade , false , context ) );
555496 collectionBinder .setOneToMany ( false );
556497 }
557498 else {
@@ -807,8 +748,8 @@ private void setInsertable(boolean insertable) {
807748 this .insertable = insertable ;
808749 }
809750
810- private void setCascadeStrategy (String cascadeStrategy ) {
811- this .cascadeStrategy = cascadeStrategy ;
751+ private void setCascadeStrategy (EnumSet < CascadeType > cascadeTypes ) {
752+ this .cascadeTypes = cascadeTypes ;
812753 }
813754
814755 private void setAccessType (AccessType accessType ) {
@@ -1267,8 +1208,8 @@ private void bindProperty() {
12671208 PropertyBinder binder = new PropertyBinder ();
12681209 binder .setName ( propertyName );
12691210 binder .setValue ( collection );
1270- binder .setCascade ( cascadeStrategy );
1271- if ( cascadeStrategy != null && cascadeStrategy .contains ( "delete-orphan" ) ) {
1211+ binder .setCascade ( cascadeTypes );
1212+ if ( cascadeTypes != null && cascadeTypes .contains ( DELETE_ORPHAN ) ) {
12721213 collection .setOrphanDelete ( true );
12731214 }
12741215 binder .setLazy ( collection .isLazy () );
0 commit comments