There seems to be a problem with mapping multiple indexes for a column, for example when adding indexes for optimisation into the hbm file.
Both Hibernate version 1.2.0.GA and 2.0.0.Alpha1 are affected
For example
Code:
<property name="Prop" type="int" >
<column name="Prop" not-null="true" unique-key="IDX_Prop" index="IDX_PropData, IDX_PropData2"/>
</property>
It's caused by
NHibernate.Cfg.HbmBinder calling
StringTokeniser in such a way that it returns the delimiters. These commas/spaces are interpreted as new index names and naturally cause invalid database scripts.
It can be simply resolved in 1.2.0.GA in
NHibernate.Cfg.HbmBinder.BindIndex and
BindUniqueKey by passing false to the StringTokenizer's returnDelims parameter:
Code:
private static void BindIndex(XmlAttribute indexAttribute, Table table, Column column, Mappings mappings)
{
if (indexAttribute != null && table != null)
{
StringTokenizer tokens = new StringTokenizer(indexAttribute.Value, ", ", false);
foreach (string token in tokens)
{
table.GetIndex(token).AddColumn(column);
}
}
}
private static void BindUniqueKey(XmlAttribute uniqueKeyAttribute, Table table, Column column, Mappings mappings)
{
if (uniqueKeyAttribute != null && table != null)
{
StringTokenizer tokens = new StringTokenizer(uniqueKeyAttribute.Value, ", ", false);
foreach (string token in tokens)
{
table.GetUniqueKey(token).AddColumn(column);
}
}
}
and similarly in 2.0.0.Alpha1 by equivalent changes to the abstract
ClassBinder and the
ClassIdBinder and
CollectionBinder
Would a patch file for this be useful?