-->
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.  [ 5 posts ] 
Author Message
 Post subject: Duplicate collection role mapping
PostPosted: Sun Feb 17, 2008 12:47 pm 
Newbie

Joined: Sun Feb 17, 2008 12:39 pm
Posts: 3
Location: dallas, TX
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2.1.4000

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="QuickStart" assembly="QuickStart">

<class name="Cat" table="Cat" lazy="false">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id" type="Int64" column="CatId" unsaved-value="0">
<generator class="identity"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="QuickStart" assembly="QuickStart">
<class name="House" table="House" lazy="false">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id" type="Int64" column="HouseID" unsaved-value="0">
<generator class="native"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="LastName">
<column name="LastName" length="16" not-null="true" />
</property>

<bag name="Cats" lazy="false">
<key column="CatID" />
<one-to-many class="Cat" />
</bag>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
[DuplicateMappingException: Duplicate collection role mapping QuickStart.House.Cats]
NHibernate.Cfg.Mappings.AddCollection(Collection collection) +111
NHibernate.Cfg.HbmBinder.PropertiesFromXML(XmlNode node, PersistentClass model, Mappings mappings) +235
NHibernate.Cfg.HbmBinder.BindRootClass(XmlNode node, RootClass model, Mappings mappings) +2404
NHibernate.Cfg.HbmBinder.BindRoot(XmlDocument doc, Mappings mappings) +390
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +64

[MappingException: Could not compile the mapping document: QuickStart.House.hbm.xml]
NHibernate.Cfg.Configuration.LogAndThrow(MappingException me) +38
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument doc) +150
NHibernate.Cfg.Configuration.ProcessMappingsQueue() +12
NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name) +169
NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly) +177
NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly) +97
QuickStart.NHibernateHelper..cctor() in C:\Workspace\QuickStart\QuickStart\Default.aspx.cs:87

[TypeInitializationException: The type initializer for 'QuickStart.NHibernateHelper' threw an exception.]
QuickStart.NHibernateHelper.GetCurrentSession() in C:\Workspace\QuickStart\QuickStart\Default.aspx.cs:103
QuickStart._Default.Page_Load(Object sender, EventArgs e) in C:\Workspace\QuickStart\QuickStart\Default.aspx.cs:23
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061


Name and version of the database you are using: SQL Server 2005 express (named instance)

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html

I'm very new to NHibernate. Please help me. I'm trying to get the QuickStart sample up and running with minor changes. I have a table House which shares a 1 to many relationship with the table Cat. I have two mapping files one for Cat and one for House, which I've attached with this message. I'm not able to get past this issue. Please help.

_________________
A Samy


Top
 Profile  
 
 Post subject: Duplicate collection role mapping
PostPosted: Sun Feb 17, 2008 2:53 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

I'm not sure if this is the problem or not, but where you have:
Code:
<bag name="Cats" lazy="false">
    <key column="CatID" />
    <one-to-many class="Cat" />
</bag>


I would've expected:
Code:
<bag name="Cats" lazy="false">
    <key column="HouseID" />
    <one-to-many class="Cat" />
</bag>


That is, it is the HouseID column from the Cats table that defines the collection of Cats for a given House. (I'm am assuming, of course, that your Cats table has a HouseID column in it.)

Regards,
Richard


Top
 Profile  
 
 Post subject: Still not working...
PostPosted: Sun Feb 17, 2008 4:48 pm 
Newbie

Joined: Sun Feb 17, 2008 12:39 pm
Posts: 3
Location: dallas, TX
Thanks, Richard for your comment. I changed the mapping files as follows:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="QuickStart" assembly="QuickStart">

<class name="Cat" table="Cat" lazy="false">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id" type="Int64" column="CatId" unsaved-value="0">
<generator class="identity"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="Name">
<column name="Name" length="16" not-null="true" />
</property>
<property name="Sex" />
<property name="Weight" />
<many-to-one name="House" class="House" column="HouseID" />
</class>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="QuickStart" assembly="QuickStart">
<class name="House" table="House" lazy="false">

<!-- A 32 hex character is our surrogate key. It's automatically
generated by NHibernate with the UUID pattern. -->
<id name="Id" type="Int64" column="HouseID" unsaved-value="0">
<generator class="native"/>
</id>
<!-- A cat has to have a name, but it shouldn' be too long. -->
<property name="LastName">
<column name="LastName" length="16" not-null="true" />
</property>
<bag name="Cats" lazy="false">
<key column="HouseID" />
<one-to-many class="Cat" />
</bag>
</class>
</hibernate-mapping>


Unfortunately, I'm still getting the same error. Any help is greatly appreciated.

_________________
A Samy


Top
 Profile  
 
 Post subject: Still not working...
PostPosted: Sun Feb 17, 2008 5:31 pm 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Is it possible that the Assembly is being added twice?

e.g., you have both a call to .AddAssembly("AssemblyName") in your startup code, and a line in your config file '<mapping assembly="AssemblyName" />'. Only one of these would be required.

Richard


Top
 Profile  
 
 Post subject: Past that issue...
PostPosted: Mon Feb 18, 2008 5:55 pm 
Newbie

Joined: Sun Feb 17, 2008 12:39 pm
Posts: 3
Location: dallas, TX
Thanks, Richard. You were right. I had multiple declarations of the assembly. I've not quiet figured it out, yet, but when I removed the reference to Cat from my SessionFactory code, it started working.

_________________
A Samy


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

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.