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 :)