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.  [ 1 post ] 
Author Message
 Post subject: NHibernate + SQLite.NET Driver Problem
PostPosted: Sat Sep 08, 2007 5:28 am 
Newbie

Joined: Sat Sep 08, 2007 4:40 am
Posts: 1
I try for 2 days to run a simple web application working on a sqlite database with NHibernate, i'm not an expert but i try A LOT of things without finding a solution.

I'm using NHibernate 1.2.0.GA and SQLite.NET
( SQLite-1.0.44.0-setup.exe from http://sourceforge.net/projects/sqlite-dotnet2 )

The Exception was:

System.TypeInitializationException was unhandled by user code
Message="L'inizializzatore di tipo di 'Nested' ha generato un'eccezione."
Source="NHibernateStuff"
TypeName="Nested"
StackTrace:
in NHibernateStuff.Utility.NHibernateSessionManager.get_Instance() in C:\Sites\MySite\NHibernateStuff\Utility\NHibernateSessionManager.cs:riga 29
in NHibernateSample.Web.NHibernateSessionModule.BeginTransaction(Object sender, EventArgs e)
in System.Web.HttpAplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
in System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)


Could not create the driver from NHibernate.Driver.SQLiteDriver.


My NHibernate configuration:

<nhibernate>
<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=C:\Sites\MySite\database\Users.db;Version=3"/>
<add key="hibernate.query.substitutions" value="true=1;false=0"/>
</nhibernate>


I try with "hibernate.connection.driver_class" set to SQLite20Driver, SQLiteDriver and then with a custom Driver Class that i find somewhere, but it doesn't work...

The driver class:
(I noticed the comment so i tried to use the NHibernate 1.2.0 Driver class after that)

/*
* TODO: This is a backport from the SQLite driver from NHibernate 1.2.0b2
* Need to be removed when NHibernate 1.2.0 final is out
*/


namespace NHibernateStuff.Utility
{

public class SQLite20Driver : ReflectionBasedDriver
{
public SQLite20Driver()
: base(
"System.Data.SQLite",
"System.Data.SQLite.SQLiteConnection",
"System.Data.SQLite.SQLiteCommand")
{
}

public override bool UseNamedPrefixInSql
{
get { return true; }
}

public override bool UseNamedPrefixInParameter
{
get { return true; }
}

public override string NamedPrefix
{
get { return "@"; }
}

public override bool SupportsMultipleOpenReaders
{
get { return false; }
}

}
}[/code]



I use NHibernateSessionManager and NHibernateSessionModule from a NHibernateBestPractices example.
( http://www.cnitblog.com/seeyeah/archive ... 24310.html )

public sealed class NHibernateSessionManager
{
#region Thread-safe, lazy Singleton

public static NHibernateSessionManager Instance {
get {
return Nested.nHibernateSessionManager;
}
}

private NHibernateSessionManager() {
InitSessionFactory();
}

private class Nested
{
static Nested() { }
internal static readonly NHibernateSessionManager nHibernateSessionManager = new NHibernateSessionManager();
}

#endregion

private void InitSessionFactory() {
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

if (ConfigurationManager.AppSettings["HBM_ASSEMBLY"] == null ||
ConfigurationManager.AppSettings["HBM_ASSEMBLY"] == "") {
throw new ConfigurationErrorsException("NHibernateManager.InitSessionFactory: \"HBM_ASSEMBLY\" must be " +
"provided as an appSetting within your config file. \"HBM_ASSEMBLY\" informs NHibernate which assembly " +
"contains the HBM files. It is assumed that the HBM files are embedded resources. An example config " +
"declaration is <add key=\"HBM_ASSEMBLY\" value=\"MyProject.Core\" />");
}

cfg.AddAssembly(System.Configuration.ConfigurationManager.AppSettings["HBM_ASSEMBLY"]);
sessionFactory = cfg.BuildSessionFactory();
}

public void RegisterInterceptor(IInterceptor interceptor) {
ISession session = threadSession;

if (session != null && session.IsOpen) {
throw new CacheException("You cannot register an interceptor once a session has already been opened");
}

GetSession(interceptor);
}

public ISession GetSession() {
return GetSession(null);
}

private ISession GetSession(IInterceptor interceptor) {
ISession session = threadSession;

if (session == null) {
if (interceptor != null) {
session = sessionFactory.OpenSession(interceptor);
}
else {
session = sessionFactory.OpenSession();
}

threadSession = session;
}

return session;
}

public void CloseSession() {
ISession session = threadSession;
threadSession = null;

if (session != null && session.IsOpen) {
session.Close();
}
}

public void BeginTransaction() {
ITransaction transaction = threadTransaction;

if (transaction == null) {
transaction = GetSession().BeginTransaction();
threadTransaction = transaction;
}
}

public void CommitTransaction() {
ITransaction transaction = threadTransaction;

try {
if (transaction != null && !transaction.WasCommitted && !transaction.WasRolledBack) {
transaction.Commit();
threadTransaction = null;
}
}
catch (HibernateException ex) {
RollbackTransaction();
throw ex;
}
}

public void RollbackTransaction() {
ITransaction transaction = threadTransaction;

try {
threadTransaction = null;

if (transaction != null && !transaction.WasCommitted && !transaction.WasRolledBack) {
transaction.Rollback();
}
}
catch (HibernateException ex) {
throw ex;
}
finally {
CloseSession();
}
}

private ITransaction threadTransaction {
get {
return (ITransaction)CallContext.GetData("THREAD_TRANSACTION");
}
set {
CallContext.SetData("THREAD_TRANSACTION", value);
}
}

private ISession threadSession {
get {
return (ISession)CallContext.GetData("THREAD_SESSION");
}
set {
CallContext.SetData("THREAD_SESSION", value);
}
}

private ISessionFactory sessionFactory;
}




Sorry for the post length but i don't want to forgot something important!

Thx 2 all anyway


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.