@@ -628,7 +628,14 @@ public void Sort()
628
628
private void AddParentChildEntityNames ( EntityInsertAction action , BatchIdentifier batchIdentifier )
629
629
{
630
630
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
+ }
632
639
633
640
for ( var i = 0 ; i < propertyValues . Length ; i ++ )
634
641
{
@@ -637,8 +644,13 @@ private void AddParentChildEntityNames(EntityInsertAction action, BatchIdentifie
637
644
if ( type . IsEntityType && value != null )
638
645
{
639
646
var entityType = ( EntityType ) type ;
640
- var entityName = entityType . Name ;
641
- batchIdentifier . ParentEntityNames . Add ( entityName ) ;
647
+ // NHibernate has non constrained one-to-one among its state while it seems Hibernate does not.
648
+ // We have to filter them out, since they are indeed children, not parents.
649
+ if ( ! ( entityType . IsOneToOne && entityType . IsNullable ) )
650
+ {
651
+ var entityName = entityType . Name ;
652
+ batchIdentifier . ParentEntityNames . Add ( entityName ) ;
653
+ }
642
654
}
643
655
else if ( type . IsCollectionType && value != null )
644
656
{
0 commit comments