Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nh 3899 Fixes to avoid too long column aliases #503

Merged
merged 3 commits into from Aug 20, 2016

Conversation

oskarb
Copy link
Member

@oskarb oskarb commented Aug 20, 2016

@oskarb oskarb merged commit fad699d into nhibernate:master Aug 20, 2016
@oskarb oskarb added this to the 4.1.0 milestone Aug 20, 2016
@hazzik
Copy link
Member

hazzik commented Nov 13, 2016

This, for some reasons, led to a duplicate alias generation.

Before:

SELECT
    this_.Name as Name2_2_,
    morechildr4_.parentName as parentName,
    child1_.Name as childName,
    morechildr4_.loc as loc,
    child1_.Name as Name0_0_,
    friends6_.childName1 as childName1_,
    child2_.Name as childName2_,
    child2_.Name as Name0_1_ 
FROM
    Parent this_ 
    inner join ParentChild morechildr4_ on this_.Name=morechildr4_.parentName 
    inner join Child child1_ on morechildr4_.childName=child1_.Name 
    inner join ChildChild friends6_ on child1_.Name=friends6_.childName1 
    inner join Child child2_ on friends6_.childName2=child2_.Name 

ORDER BY 
    this_.Name desc

After:

SELECT 
    this_.Name as Nam1_3915_2_, 
    morechildr4_.parentName as parentNa1_, 
    child1_.Name as childNam2_, 
    morechildr4_.loc as loc3_, 
    child1_.Name as Nam1_3913_0_, 
    friends6_.childName1 as childNam1_, 
    child2_.Name as childNam2_, 
    child2_.Name as Nam1_3913_1_ 

FROM Parent this_ 
    inner join ParentChild morechildr4_ on this_.Name=morechildr4_.parentName 
    inner join Child child1_ on morechildr4_.childName=child1_.Name 
    inner join ChildChild friends6_ on child1_.Name=friends6_.childName1 
    inner join Child child2_ on friends6_.childName2=child2_.Name 

ORDER BY 
    this_.Name desc

@oskarb
Copy link
Member Author

oskarb commented Nov 14, 2016

I've been looking at this earlier today actually.

The reason it worked before the change is mostly by accident:

  • In line 4 (of the SQL as above), ParentChild.childName is returned as-is from GetAlias() because it contains no digits and is less than 10 characters.
  • In line 7 and 8, ChildChild.childName1 and childName2 both gets the digit cut off and because the remainder is clearly not equal to the full column name, the suffix is added (which happens to contain the same digit as the one cut off).

If for example ParentChild.childName had instead been named childName7 in the mapping, the digit would have been cut and the 2_ suffix added, causing the same issue.

In Hibernate, the AbstractCollectionPersister also includes the table in two of four calls to GetAlias(), which NHibernate doesn't. Adding them fixes this. Working on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants