@@ -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
{
@@ -638,7 +645,16 @@ private void AddParentChildEntityNames(EntityInsertAction action, BatchIdentifie
638
645
{
639
646
var entityType = ( EntityType ) type ;
640
647
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
+ }
642
658
}
643
659
else if ( type . IsCollectionType && value != null )
644
660
{
0 commit comments