-->
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.  [ 3 posts ] 
Author Message
 Post subject: Creation of the config file
PostPosted: Fri Jan 25, 2008 3:52 am 
Beginner
Beginner

Joined: Mon Jan 21, 2008 8:57 am
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="NHibernate.Examples.QuickStart2.User, QuickStart2" table="users">
<id name="Id" column="LogonId" type="String" length="20">
<generator class="assigned" />
</id>
<property name="UserName" column="Name" type="String" length="40"/>
<property name="Password" type="String" length="20"/>
<property name="EmailAddress" type="String" length="40"/>
<property name="LastLogon" type="DateTime"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

Configuration cfg = new Configuration();
try
{
cfg.AddXmlFile(@"C:\SSWF\RequirementsContentManagement\Test\QuickStart2\QuickStart2\User.hbm.xml");
}
catch (Exception ex)
{
}
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
ITransaction transaction = session.BeginTransaction();

User newUser = new User();
newUser.Id = "Joe_cool";
newUser.Username = "Joseph Cool";
newUser.Password = "secret";
newUser.EmailAdresses = "joe@joe.com";
newUser.LastLogon = DateTime.Now;

session.Save(newUser);

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

Full stack trace of any exception that occurs:
NHibernate.HibernateException was unhandled
Message="The hibernate.connection.driver_class must be specified in the NHibernate configuration section."
Source="NHibernate"
StackTrace:
at NHibernate.Connection.ConnectionProvider.ConfigureDriver(IDictionary settings)
at NHibernate.Connection.UserSuppliedConnectionProvider.Configure(IDictionary settings)
at NHibernate.Connection.ConnectionProviderFactory.NewConnectionProvider(IDictionary settings)
at NHibernate.Cfg.SettingsFactory.BuildSettings(IDictionary properties)
at NHibernate.Cfg.Configuration.BuildSettings()
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at NHibernate.Examples.QuickStart2.queryObjects.query() in C:\SSWF\RequirementsContentManagement\Test\QuickStart2\QuickStart2\queryObjects.cs:line 22
at NHibernate.Examples.QuickStart2.Form1.button1_Click(Object sender, EventArgs e) in C:\SSWF\RequirementsContentManagement\Test\QuickStart2\QuickStart2\Form1.cs:line 21
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 NHibernate.Examples.QuickStart2.Program.Main() in C:\SSWF\RequirementsContentManagement\Test\QuickStart2\QuickStart2\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()



Name and version of the database you are using:
MSSQL 2000



Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hi,
I am following this tutorial: http://www.hibernate.org/362.html
But I get an error when I try to create the ISessionFactory. It complains about the hibernate.connection.driver_class is not specified in the NHibernate configuration section. I have created the config file and named it app.config. Do I need to do anything else to explain .net that it is my config file?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 10:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Jun 13, 2006 11:29 pm
Posts: 315
Location: Calgary, Alberta, Canada
The quick start guide is somewhat out dated. Please have a look at the reference doc here instead for set up of the config section:
http://www.hibernate.org/hib_docs/nhibe ... tart-intro

I will put it on my to-do list to update the guide.

_________________
Karl Chu


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 25, 2008 12:37 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Here is my config file template. Note, some of the things specified are defaulted already by nhibernate, but it's nice to have them called out in order to be able to control them later (proxy_validator for instance)

<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler,
NHibernate" />
</configSections>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<session-factory>
<property name="hibernate.dialect">
NHibernate.Dialect.MsSql2000Dialect
</property>
<property name="hibernate.default_schema">
{database}.{schema} <!--eg Northwinds.dbo -->
</property>
<property name="hibernate.connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="hibernate.connection.connection_string">
{ConnectionString}
</property>
<property name="hibernate.show_sql">
true
</property>
<property name="hibernate.connection.driver_class">
NHibernate.Driver.SqlClientDriver
</property>
<property name="hibernate.connection.isolation">
ReadCommitted
</property>
<property name="hibernate.use_proxy_validator">
True
</property>

<mapping assembly="{assembly name}" />
</session-factory>
</hibernate-configuration>
</configuration>

If all of your mapping files are stored in one assembly, then you can specify that assembly in the config file.

I then configure my session factory like this:

sessionFactory = new Configuration().Configure().BuildSessionFactory();


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.