Java Mailing List Archive

http://www.gg3721.com/

Home » the NHibernate development list »

[NHibernate-development] Database constraint names and hash
 collision

Alun Harford

2008-07-14

Replies: Find Java Web Hosting

Author LoginPost Reply

Hello all,

 

namespace NHibernate.Mapping

{

...

public class Table : IRelationalModel

{

...

public string UniqueColumnString(IEnumerable iterator, string referencedEntityName)

{

                ...

return (name.GetHashCode().ToString("X") + result.GetHashCode().ToString("X")); // Ouch!

}

}

}

 

We’ve just hit a problem on this line where we have two constraints on the same table.

 

Because they’re on the same table, name is the same.

And we have found a hash collision on result, due to weakness in how result is being generated.

 

Adding hashes together for string hashes isn’t safe.

 

In our case,

"BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyA".GetHashCode()+"itestmanyaid".GetHashCode()

Is equal to:

"BluewireTechnologies.Core.Framework.DynamicTypes2.Albatross.ITestManyB".GetHashCode()+"itestmanybid".GetHashCode()

 

On V2 runtime.

Changing this code would cause the schemas NHibernate generates to change :-(

 

How much of people’s code would this break? (I don’t use NHibernate in a very conventional way, so I’m not very familiar with this)

 

Is it worth submitting a patch, or are we going to have to live with the broken behaviour for backwards compatibility?

 

Alun Harford

-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_______________________________________________
Nhibernate-development mailing list
Nhibernate-development@(protected)
https://lists.sourceforge.net/lists/listinfo/nhibernate-development
©2008 gg3721.com - Jax Systems, LLC, U.S.A.