-->
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: Jet (access) Dialect with spaces in column names.
PostPosted: Tue May 09, 2006 10:10 pm 
Newbie

Joined: Tue May 31, 2005 11:19 pm
Posts: 11
Location: Brisbane, Australia
Hi,

I'm attempting to use NHibernate to connect to an existing Access 2000 database (modifying the db schema is not an option) via the Jet driver and dialect.

the column names have spaces in them which seems to be causing an issue with SQL generation.

NHibernate / Nhibernate-contrib version: 1.0.2

Mapping Extract:
Code:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
  <class name="ematter.enrolinks.model.Student, enrolinks.model" table="Students">
    <id name="Id" type="Int32" column="StudentID">
      <generator class="identity" />
    </id>
    <property name="FamilyName" column="[Family Name]" type="String" />
    <property name="FirstName" column="[First Name]" type="String" />
  </class>
</hibernate-mapping>


Config:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
    <session-factory>
        <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
        <property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</property>
       <!--<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property> -->
        <property name="connection.driver_class">NHibernate.JetDriver.JetDriver, NHibernate.JetDriver</property>
        <property name="connection.connection_string">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=G:\Inetpub\wwwroot\enrolinks3\data\enrolinks-data.mdb;</property>
        <property name="show_sql">true</property>
       <mapping assembly="enrolinks.model" />
    </session-factory>

</hibernate-configuration>



Hibernate query code:
Code:
IQuery query = NHSession.CreateQuery("from Student");
            IList result = query.List();
            
            foreach (Student s in result)
            {
               Console.WriteLine(string.Format("Student: {0} {1}", s.FirstName, s.FamilyName));
               
            }


This setup generates the following SQL:

Code:
student0_.StudentID as StudentID, student0_.[Family Name] as [Family 2_, student0_.[First Name] as [First N3_ from Students student0_


the names after 'as' are missing a closing ']' - causing this exception:

Code:
System.Data.OleDb.OleDbException: Invalid bracketing of name 'Family 2_, student0_.[First Name'


The query is simple enough for me to be able to swap in the MSSQL dialect:

Code:
NHibernate.Dialect.MsSql2000Dialect


which works as expected producing the following sql:

Code:
select student0_.StudentID as StudentID, student0_.[Family Name] as
[Family N2_], student0_.[First Name] as [First Na3_] from Students student0_


I'm going to start poking about in the Jet dialect code to see if I can find what's causing this difference between the jet and mssql dialects but if anyone has any suggestions on where to start, they would be greatly appreciated :)


Top
 Profile  
 
 Post subject: Update - Fixed!
PostPosted: Tue May 09, 2006 11:10 pm 
Newbie

Joined: Tue May 31, 2005 11:19 pm
Posts: 11
Location: Brisbane, Australia
The following change in JetDialect.cs seems to work:

Code:
                /// <summary></summary>
      public override char CloseQuote
      {
         get { return ']'; }
      }

      /// <summary></summary>
      public override char OpenQuote
      {
         get { return '['; }
      }



I don't know whether this change would have any other adverse effects...


Top
 Profile  
 
 Post subject: Re: Update - Fixed!
PostPosted: Wed May 10, 2006 9:24 am 
Newbie

Joined: Wed Sep 28, 2005 12:57 pm
Posts: 3
Location: Aberdeen, UK
brendanrichards wrote:
The following change in JetDialect.cs seems to work:

Code:
                /// <summary></summary>
      public override char CloseQuote
      {
         get { return ']'; }
      }

      /// <summary></summary>
      public override char OpenQuote
      {
         get { return '['; }
      }



I don't know whether this change would have any other adverse effects...


Not sure if it would solve your problem, but try to exchange the [First Name] with `First Name` in your mapping file with the unmodified Jet Dialect..


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.