Hi, I've been using NHibernate for a while now, and these days I encounter a "funny" problem. I am not entirely sure if it's a bug so I followed the indications regarding posting bugs and I decided to first ask about it on this forum.
Suppose we have the following classes: namespace TestBidirectional { public class Bid { private int _id; public int Id { get { return _id; } set { _id = value; } }
public string Name { get; set; }
public Item Item { get; set; } }
public class Item { private int _id; private IList<Bid> _bids = new List<Bid>(); public int Id { get { return _id; } set { _id = value; } }
public IList<Bid> Bids { get { return _bids; } }
public string Name { get; set; } } }
and corresponding mappings:
<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestBidirectional" namespace="TestBidirectional">
<class name="Bid" table="_BIDIRECTIONAL_BID" lazy="false"> <id name="Id" type="Int32" access="nosetter.camelcase-underscore"> <generator class="identity" /> </id> <property name="Name" column="`NAME`" type="string" length="50" /> <many-to-one name="Item" column="ITEM_ID" class="Item" not-null="true"/> </class> </hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="TestBidirectional" namespace="TestBidirectional"> <class name="Item" table="BIDIRECTIONAL_ITEM" lazy="false"> <id name="Id" type="Int32" access="nosetter.camelcase-underscore"> <generator class="identity" /> </id> <property name="Name" column="`NAME`" type="string" length="50" /> <bag name="Bids" inverse="true" cascade="all-delete-orphan" access="nosetter.camelcase-underscore"> <key> <!--doesn't work generating tables for bidirectional classes when using backticks - error about using 2 times the same column name!!--> <column name="`ITEM_ID`" /> <!-- in this case it works: <column name="ITEM_ID" />--> </key> <one-to-many class="Bid"/> </bag> </class> </hibernate-mapping>
Now when I try to create my tables using something like:
SchemaExport exp = new NHibernate.Tool.hbm2ddl.SchemaExport(config); exp.Execute(false, true, false, false);
NHibernate raises the following error: HNibernate.HibernateException:"Column names in each table must be unique. Column name 'ITEM_ID' in table '_BIDIRECTIONAL_BID' is specified more than once." which is actually the message from inner System.Data.SqlClient.SqlException.
Removing backticks solves the problem though. Is it a normal behaviour for foreign key columns or a NHibernate bug?
Thanks
Dan.
|