Skip to content

Commit

Permalink
HHH-17380 Persisting an entity with a non generated id and @mapsid th…
Browse files Browse the repository at this point in the history
…rows PropertyValueException
  • Loading branch information
dreab8 authored and beikov committed Jan 5, 2024
1 parent a476288 commit ed107f8
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
import org.hibernate.graph.spi.RootGraphImplementor;
import org.hibernate.id.Assigned;
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
import org.hibernate.id.ForeignGenerator;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.id.OptimizableGenerator;
import org.hibernate.id.PostInsertIdentityPersister;
Expand Down Expand Up @@ -3924,13 +3925,16 @@ public Boolean isTransient(Object entity, SharedSessionContractImplementor sessi
return false;
}
}
final Boolean unsaved = identifierMapping.getUnsavedStrategy().isUnsaved( id );
if ( unsaved != null && !unsaved ) {
throw new PropertyValueException(
"Detached entity with generated id '" + id + "' has an uninitialized version value '" + version + "'",
getEntityName(),
getVersionColumnName()
);
final Generator identifierGenerator = getGenerator();
if ( identifierGenerator != null && !( identifierGenerator instanceof ForeignGenerator ) ) {
final Boolean unsaved = identifierMapping.getUnsavedStrategy().isUnsaved( id );
if ( unsaved != null && !unsaved ) {
throw new PropertyValueException(
"Detached entity with generated id '" + id + "' has an uninitialized version value '" + version + "'",
getEntityName(),
getVersionColumnName()
);
}
}
}
return isUnsaved;
Expand Down

0 comments on commit ed107f8

Please sign in to comment.