-->
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.  [ 3 posts ] 
Author Message
 Post subject: Bug with SqlDataReader and column names like [Order]
PostPosted: Thu Jan 19, 2006 8:36 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
I found a bug, or at least a serious problem:
When the index column in a many-to-many relation with a sorted list is named 'Order', then NHibernate crashes when loading collections from this relation.

The reason is that in my mapping file I have to put in [Order] because Order is a SQL keyword. Upon loading the collection NHibernate uses the string [Order] to lookup the field index in a SqlDataReader, which fails miserably with a IndexOutOfBoundsException.

With the build 1.0.2 (downloaded today) the exception happens in file Driver\NHybridDataReader.cs in line 362, GetOrdinal(name). And yes, I'm very proud that I debugged this problem myself :-)

Now, it'd be questionable if I should use column names that are keywords. However, nothing in NHibernate is preventing me from doing that. So I'll leave it to the community to determine whether this is a bug or I have a crappy DB design ;-)

Take care, Christoph


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 8:44 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 11:38 am
Posts: 28
I forgot to mention:
I built NHibernate using .Net 1.1 and run it against a SQL2005 database. Don't know if it's any different with SQL2000.

Here is what my mapping for many-to-many looks like:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">

<class name="DataAccess.DomainModel.FaultEntry, DataAccess" table="Fault">
<id name="ID" column="ID" access="field.pascalcase-m-underscore" type="System.Guid">
<generator class="assigned" />
</id>

<list name="Diagnoses" table="FaultDiagnosis" cascade="all">
<key column="FaultID" />
<index column="[Order]"/>
<many-to-many column="DiagnosisID" class="DataAccess.DomainModel.DiagnosisEntry, DataAccess"/>
</list>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 19, 2006 10:30 pm 
Regular
Regular

Joined: Mon May 16, 2005 1:35 am
Posts: 67
Try enclosing the Order token in back-ticks (`) in your mapping file, rather than square brackets. This tells NHibernate the token is a SQL keyword and to treat it appropriately.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.