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.  [ 6 posts ] 
Author Message
 Post subject: Dialect not set.
PostPosted: Thu Jun 07, 2007 4:05 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
Hibernate version:
1.2.0 GA
Session Factory Code
Code:
public class SessionSource
    {
        #region private members

        private bool initialized = false;
        private ISessionFactory factory;

        #endregion

        #region public properties

        /// <summary>
        /// Returns true if the SessionSource has been initialized successfully.
        /// </summary>
        public bool IsInitialized
        {
            get { return initialized; }
        }

        #endregion

        #region singleton implementation

        private static SessionSource current = new SessionSource();
        public static SessionSource Current
        {
            get { return current; }
        }

        #endregion


        private SessionSource()
        {
            //prevent direct creation
        }

        /// <summary>
        /// Reads the NHibernate configuration and builds the session factory.
        /// </summary>
        public void Initialize()
        {
            Configuration config = new Configuration();
            config.AddAssembly("SocksCDS");

            factory = config.BuildSessionFactory();

            initialized = true;
        }

        /// <summary>
        /// Closes the current session factory.  The next call
        /// to initialize or GetSession will re-initialize the SessionSource
        /// </summary>
        public void Close()
        {
            if (factory == null)
                return;

            factory.Close();
            initialized = false;
        }

        /// <summary>
        /// Gets an open NHibernate ISession for work with the database.
        /// </summary>       
        /// <returns>ISession</returns>
        public ISession GetSession()
        {
            //if we aren't initialized, do it
            if (! initialized)
                Initialize();

            return factory.OpenSession();
        }

        /// <summary>
        /// Gets an open NHibernate ISession (using the existing connection) for work with the database
        /// </summary>
        /// <param name="connection">An existing IDbConnection</param>
        /// <returns>ISession</returns>
        public ISession GetSession(IDbConnection connection)
        {
            //if we aren't initialized, do it
            if (!initialized)
                Initialize();

            return factory.OpenSession(connection);
        }

        /// <summary>
        /// Gets an open NHibernate ISession for work with the database.
        /// </summary>
        /// <param name="interceptor">A custom interceptor to attach to the session before returning it.</param>
        /// <returns></returns>
        public ISession GetSession(IInterceptor interceptor)
        {
            if (!initialized)
                Initialize();

            return factory.OpenSession(interceptor);
        }
       
    }


Code between sessionFactory.openSession() and session.close():
Code:
ISession session = SessionSource.Current.GetSession();   
            ITransaction transaction = session.BeginTransaction();
                    Client newClient = new Client();
                    newClient.PhoneNumber = txtClientPhoneNumber.Text;
                    newClient.Sex = txtClientSex.Text;
                    newClient.State = txtClientState.Text;
                    newClient.Zipcode = txtClientZipCode.Text;
                    newClient.LastName = txtClientLastName.Text;
                    newClient.FirstName = txtClientFirstName.Text;
                    newClient.Street = txtClientStreet.Text;
                    newClient.Clientssn = txtClientSSN.Text;
               
                 
                try
                {
                   session.Save(newClient);
                 txtClientID.Text = newClient.Clientid.ToString();
                  transaction.Commit();
                  toolStripStatusLabel1.Text = "Client Information Saved";
                }
                catch (Exception ex) {
                    Logging.LogMessageToFile(ex.ToString());
                   
                    transaction.Rollback();
                    MessageBox.Show("An Error has occured while attempting this operation. Changes aborted. /n The Error has been logged in log.txt. /n /n Please contact the developer.", "Error",
            MessageBoxButtons.OK, MessageBoxIcon.Information);
                    toolStripStatusLabel1.Text = "Task Failed";
                }

            session.Close();

Full stack trace of any exception that occurs:
NHibernate.MappingException was unhandled
Message="Could not compile the mapping document: SocksCDS.Client.hbm.xml"
Source="NHibernate"
StackTrace:
at NHibernate.Cfg.Configuration.LogAndThrow(MappingException me)
at NHibernate.Cfg.Configuration.AddValidatedDocument(XmlDocument doc, String name)
at NHibernate.Cfg.Configuration.AddXmlReader(XmlTextReader hbmReader, String name)
at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
at NHibernate.Cfg.Configuration.AddResource(String path, Assembly assembly)
at NHibernate.Cfg.Configuration.AddResources(Assembly assembly, IList resources, Boolean skipOrdering)
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly, Boolean skipOrdering)
at NHibernate.Cfg.Configuration.AddAssembly(Assembly assembly)
at NHibernate.Cfg.Configuration.AddAssembly(String assemblyName)
at SocksCDS.SessionSource.Initialize() in C:\Code Projects\New Socks CDS\Socks CDS\SessionSource.cs:line 51
at SocksCDS.SessionSource.GetSession() in C:\Code Projects\New Socks CDS\Socks CDS\SessionSource.cs:line 79
at SocksCDS.MainForm.btnSaveClientInformation_Click(Object sender, EventArgs e) in C:\Code Projects\New Socks CDS\Socks CDS\MainForm.cs:line 151
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SocksCDS.Program.Main() in C:\Code Projects\New Socks CDS\Socks CDS\Program.cs:line 18
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


The innerexception was 'Dialect was not set'.

Name and version of the database you are using:

Access 2003/Jet 4.0

I'm sure I'm missing something here, I just can't find the error.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 07, 2007 5:10 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
Here's my App.config:<br /><br />
Code:
<?xml version="1.0"?>
<configuration>
   <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections> 
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.JetDriver.JetDialect, NHibernate.JetDriver</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=|DataDirectory|\SocksCDS.mdb</property>
  </session-factory>
  </hibernate-configuration>


  <!-- This section contains the log4net configuration settings -->
  <log4net debug="false">

    <!-- Define some output appenders -->
    <appender name="trace" type="log4net.Appender.TraceAppender, log4net">
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
      </layout>
    </appender>

    <appender name="console" type="log4net.Appender.ConsoleAppender, log4net">
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
      </layout>
    </appender>

    <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">

      <param name="File" value="log.txt"/>
      <param name="AppendToFile" value="true"/>
      <param name="RollingStyle" value="Date"/>
      <param name="DatePattern" value="yyyy.MM.dd"/>
      <param name="StaticLogFileName" value="true"/>

      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
      </layout>
    </appender>

    <!-- Setup the root category, add the appenders and set the default priority -->

    <root>
      <priority value="INFO"/>
      <appender-ref ref="console"/>
    </root>
  </log4net>
   
</configuration>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 1:51 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The app.config is probably not getting picked up.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 08, 2007 7:07 am 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
sergey wrote:
The app.config is probably not getting picked up.


Yea, what bothers me about that is that I haven't changed anything from before -- well, I've added the sessionsource class, and did things the 'proper' way. ... Any thoughts as to why it's borked?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 8:36 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
bump?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 9:43 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
I was missing the config.Configure(); line before 'config.AddAssembly();

Err, closed.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.