Skip to content

Commit 638466f

Browse files
committed
HHH-18212 Small cleanups to transient check logic
1 parent 8686392 commit 638466f

File tree

1 file changed

+9
-20
lines changed
  • hibernate-core/src/main/java/org/hibernate/engine/internal

1 file changed

+9
-20
lines changed

hibernate-core/src/main/java/org/hibernate/engine/internal/Cascade.java

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@
1919
import org.hibernate.engine.spi.CollectionEntry;
2020
import org.hibernate.engine.spi.EntityEntry;
2121
import org.hibernate.engine.spi.PersistenceContext;
22+
import org.hibernate.engine.spi.SessionFactoryImplementor;
2223
import org.hibernate.engine.spi.Status;
2324
import org.hibernate.event.spi.DeleteContext;
2425
import org.hibernate.event.spi.EventSource;
2526
import org.hibernate.internal.CoreLogging;
2627
import org.hibernate.internal.CoreMessageLogger;
27-
import org.hibernate.metamodel.mapping.AttributeMapping;
28-
import org.hibernate.metamodel.mapping.AttributeMappingsList;
29-
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
3028
import org.hibernate.persister.collection.CollectionPersister;
3129
import org.hibernate.persister.entity.EntityPersister;
3230
import org.hibernate.type.AssociationType;
@@ -172,7 +170,6 @@ else if ( action.performOnLazyProperty() && type.isEntityType() ) {
172170
type,
173171
style,
174172
propertyName,
175-
persister.getAttributeMapping( i ),
176173
anything,
177174
false
178175
);
@@ -214,17 +211,16 @@ private static <T> void cascadeProperty(
214211
final Type type,
215212
final CascadeStyle style,
216213
final String propertyName,
217-
final AttributeMapping attributeMapping,
218214
final T anything,
219215
final boolean isCascadeDeleteEnabled) throws HibernateException {
220216

221217
if ( child != null ) {
222218
if ( type.isAssociationType() ) {
223219
final AssociationType associationType = (AssociationType) type;
224-
final boolean strictUnowned = eventSource.getSessionFactory()
220+
final boolean unownedTransient = eventSource.getSessionFactory()
225221
.getSessionFactoryOptions()
226222
.isUnownedAssociationTransientCheck();
227-
if ( cascadeAssociationNow( action, cascadePoint, associationType, attributeMapping, strictUnowned ) ) {
223+
if ( cascadeAssociationNow( action, cascadePoint, associationType, eventSource.getFactory(), unownedTransient ) ) {
228224
cascadeAssociation(
229225
action,
230226
cascadePoint,
@@ -254,7 +250,6 @@ else if ( type.isComponentType() ) {
254250
parent,
255251
child,
256252
(CompositeType) type,
257-
attributeMapping,
258253
anything
259254
);
260255
if ( componentPath != null ) {
@@ -390,14 +385,14 @@ private static boolean cascadeAssociationNow(
390385
CascadingAction<?> action,
391386
CascadePoint cascadePoint,
392387
AssociationType associationType,
393-
AttributeMapping attributeMapping,
394-
boolean isStrictUnownedTransienceEnabled) {
388+
SessionFactoryImplementor factory,
389+
boolean unownedTransient) {
395390
return associationType.getForeignKeyDirection().cascadeNow( cascadePoint )
396-
// For check on flush, we should only check owned associations when strictness is enforced
397-
&& ( action != CHECK_ON_FLUSH || isStrictUnownedTransienceEnabled || !isUnownedAssociation( associationType, attributeMapping ) );
391+
// For check on flush, we should only check unowned associations when strictness is enforced
392+
&& ( action != CHECK_ON_FLUSH || unownedTransient || !isUnownedAssociation( associationType, factory ) );
398393
}
399394

400-
private static boolean isUnownedAssociation(AssociationType associationType, AttributeMapping attributeMapping) {
395+
private static boolean isUnownedAssociation(AssociationType associationType, SessionFactoryImplementor factory) {
401396
if ( associationType.isEntityType() ) {
402397
if ( associationType instanceof ManyToOneType ) {
403398
final ManyToOneType manyToOne = (ManyToOneType) associationType;
@@ -412,7 +407,7 @@ else if ( associationType instanceof OneToOneType ) {
412407
}
413408
else if ( associationType.isCollectionType() ) {
414409
// for collections, we can ask the persister if we're on the inverse side
415-
return ( (PluralAttributeMapping) attributeMapping ).getCollectionDescriptor().isInverse();
410+
return ( (CollectionType) associationType ).isInverse( factory );
416411
}
417412
return false;
418413
}
@@ -425,14 +420,10 @@ private static <T> void cascadeComponent(
425420
final Object parent,
426421
final Object child,
427422
final CompositeType componentType,
428-
final AttributeMapping attributeMapping,
429423
final T anything) {
430424
Object[] children = null;
431425
final Type[] types = componentType.getSubtypes();
432426
final String[] propertyNames = componentType.getPropertyNames();
433-
final AttributeMappingsList subMappings = attributeMapping != null ?
434-
attributeMapping.asEmbeddedAttributeMapping().getEmbeddableTypeDescriptor().getAttributeMappings() :
435-
null;
436427
for ( int i = 0; i < types.length; i++ ) {
437428
final CascadeStyle componentPropertyStyle = componentType.getCascadeStyle( i );
438429
final String subPropertyName = propertyNames[i];
@@ -452,7 +443,6 @@ private static <T> void cascadeComponent(
452443
types[i],
453444
componentPropertyStyle,
454445
subPropertyName,
455-
subMappings != null && i < subMappings.size() ? subMappings.get( i ) : null,
456446
anything,
457447
false
458448
);
@@ -594,7 +584,6 @@ private static <T> void cascadeCollectionElements(
594584
elemType,
595585
style,
596586
collectionType.getRole().substring( collectionType.getRole().lastIndexOf('.') + 1 ),
597-
null,
598587
anything,
599588
isCascadeDeleteEnabled
600589
);

0 commit comments

Comments
 (0)