Skip to content

Commit 8986710

Browse files
committed
Merge pull request #407 from nhibernate/NH-1452
NH-1452 - Fix join's key column type
2 parents bc90e44 + 6b5a1e5 commit 8986710

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/NHibernate/Mapping/PersistentClass.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using NHibernate.SqlCommand;
55
using NHibernate.Util;
66
using System.Collections.Generic;
7+
using System.Linq;
78

89
namespace NHibernate.Mapping
910
{
@@ -436,15 +437,7 @@ public virtual int JoinClosureSpan
436437

437438
public virtual int PropertyClosureSpan
438439
{
439-
get
440-
{
441-
int span = properties.Count;
442-
foreach (Join join in joins)
443-
{
444-
span += join.PropertySpan;
445-
}
446-
return span;
447-
}
440+
get { return properties.Count + joins.Sum(j => j.PropertySpan); }
448441
}
449442

450443
/// <summary>

src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
276276
}
277277
}
278278

279-
batchSize = persistentClass.BatchSize.HasValue ? persistentClass.BatchSize.Value : factory.Settings.DefaultBatchFetchSize;
279+
batchSize = persistentClass.BatchSize ?? factory.Settings.DefaultBatchFetchSize;
280280
hasSubselectLoadableCollections = persistentClass.HasSubselectLoadableCollections;
281281

282282
propertyMapping = new BasicEntityPropertyMapping(this);
@@ -993,6 +993,11 @@ public virtual string IdentifierPropertyName
993993
get { return entityMetamodel.IdentifierProperty.Name; }
994994
}
995995

996+
public virtual IType GetIdentifierType(int j)
997+
{
998+
return IdentifierType;
999+
}
1000+
9961001
public virtual IType IdentifierType
9971002
{
9981003
get { return entityMetamodel.IdentifierProperty.Type; }
@@ -2241,9 +2246,9 @@ protected internal SqlCommandInfo GenerateUpdateString(bool[] includeProperty, i
22412246

22422247
// select the correct row by either pk or rowid
22432248
if (useRowId)
2244-
updateBuilder.SetIdentityColumn(new string[] { rowIdName }, NHibernateUtil.Int32); //TODO: eventually, rowIdName[j]
2249+
updateBuilder.SetIdentityColumn(new[] {rowIdName}, NHibernateUtil.Int32); //TODO: eventually, rowIdName[j]
22452250
else
2246-
updateBuilder.SetIdentityColumn(GetKeyColumns(j), IdentifierType);
2251+
updateBuilder.SetIdentityColumn(GetKeyColumns(j), GetIdentifierType(j));
22472252

22482253
bool hasColumns = false;
22492254
for (int i = 0; i < entityMetamodel.PropertySpan; i++)
@@ -2357,7 +2362,7 @@ protected virtual SqlCommandInfo GenerateInsertString(bool identityInsert, bool[
23572362
}
23582363
else
23592364
{
2360-
builder.AddColumns(GetKeyColumns(j), null, IdentifierType);
2365+
builder.AddColumns(GetKeyColumns(j), null, GetIdentifierType(j));
23612366
}
23622367

23632368
if (Factory.Settings.IsCommentsEnabled)
@@ -2407,7 +2412,7 @@ protected virtual SqlCommandInfo GenerateDeleteString(int j)
24072412
var deleteBuilder = new SqlDeleteBuilder(Factory.Dialect, Factory);
24082413
deleteBuilder
24092414
.SetTableName(GetTableName(j))
2410-
.SetIdentityColumn(GetKeyColumns(j), IdentifierType);
2415+
.SetIdentityColumn(GetKeyColumns(j), GetIdentifierType(j));
24112416

24122417
// NH: Only add version to where clause if optimistic lock mode is Version
24132418
if (j == 0 && IsVersioned && entityMetamodel.OptimisticLockMode == Versioning.OptimisticLock.Version)
@@ -3162,7 +3167,7 @@ protected SqlCommandInfo[] GenerateSQLDeleteStrings(object[] loadedState)
31623167
{
31633168
SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory)
31643169
.SetTableName(GetTableName(j))
3165-
.SetIdentityColumn(GetKeyColumns(j), IdentifierType);
3170+
.SetIdentityColumn(GetKeyColumns(j), GetIdentifierType(j));
31663171

31673172
if (Factory.Settings.IsCommentsEnabled)
31683173
{

src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class SingleTableEntityPersister : AbstractEntityPersister, IQueryable
1919
{
2020
// the class hierarchy structure
2121
private readonly int joinSpan;
22+
private IType[] identifierTypes;
2223
private readonly string[] qualifiedTableNames;
2324
private readonly bool[] isInverseTable;
2425
private readonly bool[] isNullableTable;
@@ -39,7 +40,7 @@ public class SingleTableEntityPersister : AbstractEntityPersister, IQueryable
3940
private readonly int[] propertyTableNumbers;
4041

4142
// if the id is a property of the base table eg join to property-ref
42-
// if the id is not a property the value will be -1
43+
// if the id is not a property the value will be null
4344
private readonly Dictionary<int, int> tableIdPropertyNumbers;
4445

4546
// the closure of all columns used by the entire hierarchy including
@@ -82,13 +83,14 @@ public SingleTableEntityPersister(PersistentClass persistentClass, ICacheConcurr
8283
#region CLASS + TABLE
8384

8485
joinSpan = persistentClass.JoinClosureSpan + 1;
86+
identifierTypes = new IType[joinSpan];
8587
qualifiedTableNames = new string[joinSpan];
8688
isInverseTable = new bool[joinSpan];
8789
isNullableTable = new bool[joinSpan];
8890
keyColumnNames = new string[joinSpan][];
8991
Table table = persistentClass.RootTable;
90-
qualifiedTableNames[0] =
91-
table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
92+
identifierTypes[0] = IdentifierType;
93+
qualifiedTableNames[0] =table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
9294
isInverseTable[0] = false;
9395
isNullableTable[0] = false;
9496
keyColumnNames[0] = IdentifierColumnNames;
@@ -124,6 +126,7 @@ public SingleTableEntityPersister(PersistentClass persistentClass, ICacheConcurr
124126
int j = 1;
125127
foreach (Join join in persistentClass.JoinClosureIterator)
126128
{
129+
identifierTypes[j] = join.Key.Type;
127130
qualifiedTableNames[j] = join.Table.GetQualifiedName(factory.Dialect, factory.Settings.DefaultCatalogName, factory.Settings.DefaultSchemaName);
128131
isInverseTable[j] = join.IsInverse;
129132
isNullableTable[j] = join.IsOptional;
@@ -461,6 +464,11 @@ public override string[] ConstraintOrderedTableNameClosure
461464
get { return constraintOrderedTableNames; }
462465
}
463466

467+
public override IType GetIdentifierType(int j)
468+
{
469+
return identifierTypes[j];
470+
}
471+
464472
public override string[][] ContraintOrderedTableKeyColumnClosure
465473
{
466474
get { return constraintOrderedKeyColumnNames; }

0 commit comments

Comments
 (0)