mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-03-03 16:29:13 +00:00
HHH-17380 Persisting an entity with a non generated id and @MapsId throws PropertyValueException
This commit is contained in:
parent
00340107d4
commit
ab861e99fb
@ -107,6 +107,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;
|
||||
@ -4124,13 +4125,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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user