-
Notifications
You must be signed in to change notification settings - Fork 934
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
Table mapping for UniqueColumn uses unstable GetHashCode() method #1769
Comments
Anyway using a hashcode for attempting getting something unique is a bug on its own, since hashcodes are never guaranteed unique. Another naming algorithm has to be put in place. |
Alternatively use something like https://github.com/LogosBible/Logos.Utility/blob/master/src/Logos.Utility/GuidUtility.cs to generate a cross platform stable uuid |
Hibernate fixed this problem by postponing the generation until the reference table is known, after that they generate the name by concatenating the table and the columns names and hashing the result with the MD5 algorithm in order to avoid too long names. |
We should likely do the postponing. But then, the hashing part can be troublesome, since collisions may occur, even if it is quite unlikely. Moreover it guarantees a name only shorter than thirty characters, while we have dialects having |
Worse for the .Net Core case, as written in #1791, the generated names change at each run under .Net Core. So .Net Core is in the following case:
The following code yields different strings at each run under netcoreapp2.0: [Test]
public void UniqueName()
{
var tbl = new Table { Name = "name" };
Console.Write(tbl.UniqueColumnString(new[] { "col1", "col2" }, "ent1"));
} |
The snippet below presents the way how
Table
class generatesUniqueColumn
name. This value is used in several code paths, likeCreateForeignKey
and/or generating an unique column name itself.nhibernate-core/src/NHibernate/Mapping/Table.cs
Lines 859 to 872 in c4fb3dc
string.GetHashCode
is not a stable hashing function, according to the documentationCreating the script then, can have a different outcome when run in two different environments, like
.NET Core 2.1
andnet461
or even across 32/64 bits.The text was updated successfully, but these errors were encountered: