Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/NHibernate/Persister/Entity/AbstractEntityPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public virtual void BindValues(DbCommand ps)

// This must be a Lazy<T>, because instances of this class must be thread safe.
private readonly Lazy<string[]> defaultUniqueKeyPropertyNamesForSelectId;
private readonly Dictionary<string, int> propertyTableNumbersByNameAndSubclass = new Dictionary<string, int>();
private readonly Dictionary<string, int> propertySubclassJoinTableNumbersByName;

protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory)
Expand Down Expand Up @@ -441,6 +441,17 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
List<bool> columnSelectables = new List<bool>();
List<bool> propNullables = new List<bool>();

if (persistentClass.SubclassJoinClosureIterator.Any())
{
propertySubclassJoinTableNumbersByName = new Dictionary<string, int>();
foreach (Property prop in persistentClass.SubclassPropertyClosureIterator)
{
var joinNumber = persistentClass.GetJoinNumber(prop);
if (joinNumber != 0)
propertySubclassJoinTableNumbersByName[prop.PersistentClass.EntityName + '.' + prop.Name] = joinNumber;
}
}

foreach (Property prop in persistentClass.SubclassPropertyClosureIterator)
{
names.Add(prop.Name);
Expand All @@ -449,8 +460,6 @@ protected AbstractEntityPersister(PersistentClass persistentClass, ICacheConcurr
definedBySubclass.Add(isDefinedBySubclass);
propNullables.Add(prop.IsOptional || isDefinedBySubclass); //TODO: is this completely correct?
types.Add(prop.Type);
propertyTableNumbersByNameAndSubclass[prop.PersistentClass.EntityName + '.' + prop.Name] =
persistentClass.GetJoinNumber(prop);

string[] cols = new string[prop.ColumnSpan];
string[] forms = new string[prop.ColumnSpan];
Expand Down Expand Up @@ -1125,12 +1134,15 @@ protected virtual bool IsIdOfTable(int property, int table)

protected abstract int GetSubclassPropertyTableNumber(int i);

internal int GetSubclassPropertyTableNumber(string propertyName, string entityName)
internal int GetSubclassJoinPropertyTableNumber(string propertyName, string entityName)
{
if (propertySubclassJoinTableNumbersByName == null)
return 0;

var type = propertyMapping.ToType(propertyName);
if (type.IsAssociationType && ((IAssociationType) type).UseLHSPrimaryKey)
return 0;
propertyTableNumbersByNameAndSubclass.TryGetValue(entityName + '.' + propertyName, out var tabnum);
propertySubclassJoinTableNumbersByName.TryGetValue(entityName + '.' + propertyName, out var tabnum);
return tabnum;
}

Expand Down Expand Up @@ -4878,7 +4890,7 @@ internal SqlString GenerateSequentialSelect(AbstractEntityPersister subclassPers
var classes = subclassPersister.PropertySubclassNames;
for (var i = 0; i < props.Length; i++)
{
var propTableNumber = GetSubclassPropertyTableNumber(props[i], classes[i]);
var propTableNumber = GetSubclassJoinPropertyTableNumber(props[i], classes[i]);
if (IsSubclassTableSequentialSelect(propTableNumber) && !IsSubclassTableLazy(propTableNumber))
{
tableNumbers.Add(propTableNumber);
Expand Down
6 changes: 3 additions & 3 deletions src/NHibernate/Persister/Entity/SingleTableEntityPersister.cs
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ protected override void AddDiscriminatorToInsert(SqlInsertBuilder insert)
protected override bool IsSubclassPropertyDeferred(string propertyName, string entityName)
{
return
hasSequentialSelects && IsSubclassTableSequentialSelect(base.GetSubclassPropertyTableNumber(propertyName, entityName));
hasSequentialSelects && IsSubclassTableSequentialSelect(GetSubclassPropertyTableNumber(propertyName, entityName));
}

protected override bool IsPropertyDeferred(int propertyIndex)
Expand All @@ -713,9 +713,9 @@ public override bool HasSequentialSelect

//Since v5.3
[Obsolete("This method has no more usage in NHibernate and will be removed in a future version.")]
public new int GetSubclassPropertyTableNumber(string propertyName, string entityName)
public int GetSubclassPropertyTableNumber(string propertyName, string entityName)
{
return base.GetSubclassPropertyTableNumber(propertyName, entityName);
return GetSubclassJoinPropertyTableNumber(propertyName, entityName);
}

//Since v5.3
Expand Down