Skip to content

Commit f4424ab

Browse files
NH-3931 - fix of port, NH specificities?
1 parent 6dfa5d8 commit f4424ab

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/NHibernate/Engine/ActionQueue.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,14 @@ public void Sort()
628628
private void AddParentChildEntityNames(EntityInsertAction action, BatchIdentifier batchIdentifier)
629629
{
630630
var propertyValues = action.State;
631-
var propertyTypes = action.Persister.ClassMetadata.PropertyTypes;
631+
// NH: it seems we support custom persister which does not provide meta-data (see CustomPersister in NHibernate.DomainModel).
632+
var propertyTypes = action.Persister.ClassMetadata?.PropertyTypes;
633+
if (propertyTypes == null)
634+
{
635+
log.WarnFormat("Entity {0} persister does not provide meta-data, its batch ordering may be wrong and cause a failure.",
636+
batchIdentifier.EntityName);
637+
return;
638+
}
632639

633640
for (var i = 0; i < propertyValues.Length; i++)
634641
{
@@ -638,7 +645,16 @@ private void AddParentChildEntityNames(EntityInsertAction action, BatchIdentifie
638645
{
639646
var entityType = (EntityType)type;
640647
var entityName = entityType.Name;
641-
batchIdentifier.ParentEntityNames.Add(entityName);
648+
// NHibernate has non constrained one-to-one among its state while it seems Hibernate does not.
649+
// We have to handle them specifically, since they are indeed children, not parents.
650+
if (!(entityType.IsOneToOne && entityType.IsNullable))
651+
{
652+
batchIdentifier.ParentEntityNames.Add(entityName);
653+
}
654+
else
655+
{
656+
batchIdentifier.ChildEntityNames.Add(entityName);
657+
}
642658
}
643659
else if (type.IsCollectionType && value != null)
644660
{

0 commit comments

Comments
 (0)