Hibernate version: 1.0.2
DataBase: Ms Access 2003
Hi there,
I'm upgrading a (multilanguage) application in order to run it with NHibernate v1.0.2.0 instead of v0.9.0.0. I'm encountering a problem when I try to save an object that contains a DateTime property. I already found out that my problem is related to the language (and associated culture) the user has chosen.
To illustrate the problem, I provided a small testapp, containing one object, called 'User'. At first, when I try to insert a user-object in my db every thing runs fine. (mapping file and nhibernate settings at the bottom of this post)
This code inits hibernate, creates the session and saves a user:
Code:
Configuration cfg = new Configuration();
cfg.AddAssembly("NHibernateTestApplication");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ICriteria crit = session.CreateCriteria(typeof(User));
ArrayList list = (ArrayList) crit.List();
User user = new User();
user.EmailAddress = "stijn@b.c";
user.Id = "anId";
user.LastLogon = DateTime.Now;
user.Password = "pwd";
user.UserName = "sva";
ITransaction tx = session.BeginTransaction();
session.Save(user);
tx.Commit();
session.Close();
It produces this ouput:
Code:
...
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - INSERT INTO [User] (myname, LastLogon, EmailAddress, mypassword, myLogonId) VALUES (?, ?, ?, ?, ?)
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - @p0 = 'sva'
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - @p1 = '5/05/2006 11:47:35'
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - @p2 = 'stijn@b.c'
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - @p3 = 'pwd'
2006-05-05 11:47:36,081 [532] DEBUG NHibernate.SQL - @p4 = 'anId'
...
Now, I do this again, an add this line at the beginning of my program:
Code:
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
Now, I get an 'ADOException':
Quote:
NHibernate.ADOException: could not insert: [NhibernateTestApplication.Classes.User#-1384080488] ---> System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.
The sql-output:
Code:
...
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - INSERT INTO [User] (myname, LastLogon, EmailAddress, mypassword, myLogonId) VALUES (?, ?, ?, ?, ?)
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - @p0 = 'sva'
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - @p1 = '5/5/2006 11:53:23 AM'
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - @p2 = 'stijn@b.c'
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - @p3 = 'pwd'
2006-05-05 11:53:24,004 [2420] DEBUG NHibernate.SQL - @p4 = 'anOtherId'
...
Note that the only difference between both logs is the format of the datetime-object. When it's printed in 24h-mode, everything runs fine. When it's printed in 12h-mode, due to the changed culture, the app crashes. It seems like a string is passed to access, and not a DateTime-object.
Can anyone help me out?
Thx.
Greetz,
Stijn
Mapping documents: User.hbm.xmlCode:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="NhibernateTestApplication.Classes.User, NhibernateTestApplication" table="[User]">
<id name="Id" column="myLogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="myname" type="String" length="40"/>
<property name="Password" column="mypassword" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>
Hibernate settingsCode:
<nhibernate>
<add key="hibernate.connection.provider"
value="NHibernate.Connection.DriverConnectionProvider" />
<add key="hibernate.dialect"
value="NHibernate.JetDriver.JetDialect, NHibernate.JetDriver" />
<add key="hibernate.connection.driver_class"
value="NHibernate.JetDriver.JetDriver, NHibernate.JetDriver" />
<add key="hibernate.connection.connection_string"
value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\vanassches\My Documents\Visual Studio 2005\Projects\NhibernateTestApplication\NhibernateTestApplication\test.mdb" />
</nhibernate>