Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 22 additions & 14 deletions hibernate-core/src/main/java/org/hibernate/event/spi/LoadEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.hibernate.event.spi;

import org.hibernate.Internal;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.Locking;
Expand Down Expand Up @@ -66,32 +67,36 @@ private LoadEvent(
boolean isAssociationFetch,
EventSource source,
Boolean readOnly) {

super( source );
this.entityId = entityId;
this.entityClassName = entityClassName;
this.instanceToLoad = instanceToLoad;
this.lockOptions = lockOptions;
this.isAssociationFetch = isAssociationFetch;
this.readOnly = readOnly;
validate();
}

@Internal
public void validate() {
if ( entityId == null ) {
throw new IllegalArgumentException( "id to load is required for loading" );
throw new IllegalArgumentException( "Identifier may not be null" );
}

if ( lockOptions.getLockMode() == LockMode.WRITE ) {
throw new IllegalArgumentException("Invalid lock mode for loading");
final var lockMode = lockOptions.getLockMode();
if ( lockMode == LockMode.WRITE ) {
throw new IllegalArgumentException( "Invalid lock mode: " + LockMode.WRITE );
}
else if ( lockOptions.getLockMode() == null ) {
else if ( lockMode == null ) {
lockOptions.setLockMode( LockMode.NONE );
}

this.entityId = entityId;
this.entityClassName = entityClassName;
this.instanceToLoad = instanceToLoad;
this.lockOptions = lockOptions;
this.isAssociationFetch = isAssociationFetch;
this.readOnly = readOnly;
}

public Object getEntityId() {
return entityId;
}

@Internal
public void setEntityId(Object entityId) {
this.entityId = entityId;
}
Expand All @@ -100,6 +105,7 @@ public String getEntityClassName() {
return entityClassName;
}

@Internal
public void setEntityClassName(String entityClassName) {
this.entityClassName = entityClassName;
}
Expand All @@ -108,6 +114,7 @@ public boolean isAssociationFetch() {
return isAssociationFetch;
}

@Internal
public void setAssociationFetch(boolean associationFetch) {
isAssociationFetch = associationFetch;
}
Expand All @@ -116,6 +123,7 @@ public Object getInstanceToLoad() {
return instanceToLoad;
}

@Internal
public void setInstanceToLoad(Object instanceToLoad) {
this.instanceToLoad = instanceToLoad;
}
Expand All @@ -124,6 +132,7 @@ public LockOptions getLockOptions() {
return lockOptions;
}

@Internal
public void setLockOptions(LockOptions lockOptions) {
this.lockOptions = lockOptions;
}
Expand All @@ -140,12 +149,11 @@ public Boolean getReadOnly() {
return readOnly;
}

@Internal
public void setReadOnly(Boolean readOnly) {
this.readOnly = readOnly;
}



/**
* @deprecated Use {@linkplain #getLockOptions()} instead.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,7 @@ protected LoadEvent makeLoadEvent(String entityName, Object id, Boolean readOnly
event.setReadOnly( readOnly );
event.setLockOptions( lockOptions );
event.setAssociationFetch( false );
event.validate();
return event;
}
}
Expand Down
Loading