-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Sqlite and generator
PostPosted: Mon Oct 24, 2005 5:07 pm 
Newbie

Joined: Mon Oct 24, 2005 4:54 pm
Posts: 2
Hello,
I am new to nhibernate.I am trying to use Sqlite and the value that is genetated for the primary key from Sqlite. But i can't make it work.

Here is some code from person.hbm.xml:
Code:
<class name="Glue.Person, Glue" table="person">
    <id name="Id" type="Int32"   unsaved-value="-1">
      <column name="id" sql-type="Int32" unique="true" unique-key="true" not-null="true" />
      <generator class="native" />
    </id>
    <property name="FirstName" column="firstName" type="String" />
    <property name="LastName" column="lastName" type="String" />
  </class>


Here is some code trying to add a record:
Code:
factory = cfg.BuildSessionFactory();
session =  factory.OpenSession();
transaction = session.BeginTransaction();

Person prs = new Person();
prs.Id = -1;
prs.FirstName = "MyName";
prs.LastName = "MyLastName";
session.Save(prs);

transaction.Commit();
session.Close();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 5:35 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
What is the error you're getting?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 25, 2005 11:39 am 
Newbie

Joined: Mon Oct 24, 2005 4:54 pm
Posts: 2
The error is:

"An unhandled exception of type 'NHibernate.ADOException' occurred in nhibernate.dll

Additional information: Could not save object"

The exception is ocuring at:
"session.Save(prs);"


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 5:19 pm 
defdef wrote:
The error is:

"An unhandled exception of type 'NHibernate.ADOException' occurred in nhibernate.dll

Additional information: Could not save object"

The exception is ocuring at:
"session.Save(prs);"


I dont seem to have any luck getting hibernate to work with SQLite (it was fine with SQL server 2000.

I get the following error when on BuildSessionFactory

"Could not create the driver from NHibernate.Driver.SQLiteDriver." when I do.

Has anyone any ideas? I am have installed the ADO.net 2 SQlite from the site linked to from the nhibernate site.


Top
  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 9:22 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you provide more details about your configuration settings?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 02, 2005 11:51 am 
KPixel wrote:
Can you provide more details about your configuration settings?


Hi they were copy and pasted off the sqlite page on this site.

Code:
<add key="hibernate.dialect"
     value="NHibernate.Dialect.SQLiteDialect" />

<add key="hibernate.connection.provider"
     value="NHibernate.Connection.DriverConnectionProvider" />

<add key="hibernate.connection.driver_class"
     value="NHibernate.Driver.SQLiteDriver" />

<add key="hibernate.connection.connection_string"
     value="Data Source=nhibernate.db;Version=3" />

<add key="hibernate.query.substitutions"
     value="true=1;false=0" />


Top
  
 
 Post subject:
PostPosted: Mon Dec 05, 2005 10:13 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Can you change log4net level to DEBUG and post the logs?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 11:56 am 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
I've similar problem.
here is my mapping:

Code:
<?xml version="1.0" encoding="utf-16"?>
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
  <class name="TestSQLite.Utente, TestSQLite" table="Utenti" lazy="false">
    <id name="NUid" access="property" column="NUid" type="Int32" unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <property name="Uid" access="property" column="Uid" type="Int16" />
    <property name="UserName" access="property" column="name" type="String" />
    <property name="FlgAttivo" access="property" column="FlgAttivo" type="Boolean" />
    <property name="InsUser" access="property" column="InsUser" type="String" />
    <property name="InsData" access="property" column="InsData" type="System.DateTime" />
    <property name="ModUser" access="property" column="ModUser" type="String" />
    <property name="ModData" access="property" column="ModData" type="System.DateTime" />
  </class>
</hibernate-mapping>

When I try to save my model I receive the following error:

Code:
TestCase 'TestSQLite.TestUtente.TestInserimentoUtente' failed: Castle.ActiveRecord.Framework.ActiveRecordException : Could not perform Save for Utente
  ----> NHibernate.ADOException : Could not save object
  ----> Finisar.SQLite.SQLiteException : no such table: hibernate_unique_key
   d:\progetti\castle\activerecord\castle.activerecord\framework\activerecordbase.cs(333,0): at Castle.ActiveRecord.ActiveRecordBase.Save(Object instance)
   d:\progetti\castle\activerecord\castle.activerecord\framework\activerecordbase.cs(838,0): at Castle.ActiveRecord.ActiveRecordBase.Save()
   d:\progetti\testsqlite\testutente.cs(19,0): at TestSQLite.TestUtente.TestInserimentoUtente()
   --ActiveRecordException
   at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
   at NHibernate.Impl.SessionImpl.Save(Object obj)
   at NHibernate.Impl.SessionImpl.SaveOrUpdate(Object obj)
   d:\progetti\castle\activerecord\castle.activerecord\framework\activerecordbase.cs(320,0): at Castle.ActiveRecord.ActiveRecordBase.Save(Object instance)
   --ADOException
   at Finisar.SQLite.sqlite3.Throw()
   at Finisar.SQLite.sqlite3.compile(String zSql)
   at Finisar.SQLite.OneSQLStatement.Compile()
   at Finisar.SQLite.SQLiteDataReader.ExecuteFirstStep()
   at Finisar.SQLite.SQLiteDataReader.Read()
   at NHibernate.Id.TableGenerator.Generate(ISessionImplementor session, Object obj)
   at NHibernate.Id.TableHiLoGenerator.Generate(ISessionImplementor session, Object obj)
   at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)


0 passed, 1 failed, 0 skipped, took 6.83 seconds.


But if I change the generator to <generator class="identity"> all work fine.

Where could I tell to NH that for SQLite the Native generator should use identity generator?

In the meantime I look at the code...
Bye,
Antonio.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 12:17 pm 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
It seems that the solution should be to add in the SQLiteDialect
Code:
public override bool SupportsIdentityColumns
{
   get { return true; }
}


But I cannot test because I cannot compile the project :(


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 24, 2006 2:15 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
You can write your own dialect that subclasses the SQLiteDialect, then set the config to use your dialect class.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 1:59 pm 
Newbie

Joined: Thu Oct 20, 2005 5:17 pm
Posts: 19
I don't think the version of the Sqlite DLL used in the .NET driver supports autoincrementing. It's quite old, early 2005. Someone requested instructions on updating it, but the developer hasn't responded.

http://sourceforge.net/tracker/index.ph ... tid=606538


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 5:16 am 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
I've simply replaced the old SQLite.dll and sqlite3.dll with the latest version and all work fine except for this issue... now I'm trying to subclass the SQLiteDialect in my current project without success.
I'm receiving this exception:
"Could not load type 'TestSQLite.CustomSQLiteDialect, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc', check that type and assembly names are correct"

I'm working on it.
Bye,
Antonio.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:00 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
a.carpe wrote:
"Could not load type 'TestSQLite.CustomSQLiteDialect, NHibernate, Version=1.0.2.0, Culture=neutral, PublicKeyToken=154fdcb44c4484fc'


I believe you need to specify the assembly name - something like 'TestSQLite.CustomSQLiteDialect, TestSQLite'. NHibernate will assume the class is in the NHibernate assembly unless you specify a different one.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:25 am 
Newbie

Joined: Fri Mar 24, 2006 11:42 am
Posts: 7
with "TestSQLite.CustomSQLiteDialect, TestSQLite" in app.config it works!
Thank you!
Antonio!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 11:33 am 
Newbie

Joined: Thu Oct 20, 2005 5:17 pm
Posts: 19
a.carpe wrote:
I've simply replaced the old SQLite.dll and sqlite3.dll with the latest version and all work fine except for this issue...


That's good to know. I had tried doing this and had some initial success, but I wasn't sure if it would be reliable, since I've only just started my first project using SQLite.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 16 posts ]  Go to page 1, 2  Next

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.