Skip to content

Commit ed107f8

Browse files
dreab8beikov
authored andcommitted
HHH-17380 Persisting an entity with a non generated id and @mapsid throws PropertyValueException
1 parent a476288 commit ed107f8

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@
105105
import org.hibernate.graph.spi.RootGraphImplementor;
106106
import org.hibernate.id.Assigned;
107107
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
108+
import org.hibernate.id.ForeignGenerator;
108109
import org.hibernate.id.IdentifierGenerator;
109110
import org.hibernate.id.OptimizableGenerator;
110111
import org.hibernate.id.PostInsertIdentityPersister;
@@ -3924,13 +3925,16 @@ public Boolean isTransient(Object entity, SharedSessionContractImplementor sessi
39243925
return false;
39253926
}
39263927
}
3927-
final Boolean unsaved = identifierMapping.getUnsavedStrategy().isUnsaved( id );
3928-
if ( unsaved != null && !unsaved ) {
3929-
throw new PropertyValueException(
3930-
"Detached entity with generated id '" + id + "' has an uninitialized version value '" + version + "'",
3931-
getEntityName(),
3932-
getVersionColumnName()
3933-
);
3928+
final Generator identifierGenerator = getGenerator();
3929+
if ( identifierGenerator != null && !( identifierGenerator instanceof ForeignGenerator ) ) {
3930+
final Boolean unsaved = identifierMapping.getUnsavedStrategy().isUnsaved( id );
3931+
if ( unsaved != null && !unsaved ) {
3932+
throw new PropertyValueException(
3933+
"Detached entity with generated id '" + id + "' has an uninitialized version value '" + version + "'",
3934+
getEntityName(),
3935+
getVersionColumnName()
3936+
);
3937+
}
39343938
}
39353939
}
39363940
return isUnsaved;

0 commit comments

Comments
 (0)