-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Error on creating tables for a bidirectional relation
PostPosted: Tue Nov 24, 2009 6:01 am 
Newbie

Joined: Tue Nov 24, 2009 5:37 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.