Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version: 1.0.4
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SocksCDS.Wages, SocksCDS" table="tblWages">
<id name="WagesID" column="WagesID" type="int" length="5">
<generator class="identity" />
</id>
<property name="WagesAmount" />
<property name="UnemploymentAmount" />
<property name="SSIDisabilityAmount" />
<property name="FoodStampsAmount" />
<property name="SocialSecurityAmount" />
<property name="ChildSupportAmount" />
<property name="ClientID" />
<set name="Wages" cascade="all" lazy="true">
<KEY column="ClientID" />
<MANY-TO-ONE name="Client" class="SocksCDS.Client, SocksCDS" column="ClientID" />
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SocksCDS.Client, SocksCDS" table="tblSpouse">
<id name="SpouseID" column="SpouseID" type="int" length="5">
<generator class="identity" />
</id>
<property name="SpouseLastName" />
<property name="SpouseFirstName" />
<property name="SpouseSSN" />
<property name="SpouseEmployer" />
<set name="Spouse" cascade="all" lazy="true">
<KEY column="ClientID" />
<MANY-TO-ONE name="Client" class="SocksCDS.Client, SocksCDS" column="ClientID" />
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SocksCDS.Employer, SocksCDS" table="tblEmployer">
<id name="EmployerID" column="EmployerID" type="int" length="5">
<generator class="identity" />
</id>
<property name="EmployerName" />
<property name="ClientID" />
<set name="Employer" cascade="all" lazy="true">
<KEY column="ClientID" />
<MANY-TO-ONE name="Client" class="SocksCDS.Client, SocksCDS" column="ClientID"/>
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SocksCDS.Client, SocksCDS" table="tblClient">
<id name="ClientID" column="ClientID" type="int" length="5">
<generator class="identity" />
</id>
<property name="LastName" />
<property name="FirstName" />
<property name="ClientSSN" />
<property name="Street" />
<property name="City" />
<property name="ZipCode" />
<property name="State" />
<property name="PhoneNumber" />
<property name="Sex" />
<property name="Race" />
<property name="MaritalStatus" />
<property name="AuthorizedPerson1" />
<property name="AuthorizedPerson2" />
<property name="ApplicationDate" />
<set name="Child" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Child, SocksCDS" />
</set>
<set name="Spouse" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Spouse, SocksCDS" />
</set>
<set name="Wages" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Wages, SocksCDS" />
</set>
<set name="Employer" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Employer, SocksCDS" />
</set>
<set name="Assistance" cascade="all" lazy="true">
<KEY column="ClientID" />
<ONE-TO-MANY class="SocksCDS.Assistance, SocksCDS" />
</set>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="SocksCDS.Child, SocksCDS" table="tblChildren">
<id name="ChildID" column="ChildID" type="int" length="5">
<generator class="identity" />
</id>
<property name="ChildSSN" column="ChildSSN" type="long" length="9"/>
<property name="LastName" column="LastName" type="String" length="40"/>
<property name="FirstName" column="FirstName" type="String" length="20"/>
<property name="BirthDate" column="BirthDate" type="DateTime"/>
<property name="ClientID" column="ClientID" type="long" length="5"/>
</class>
<SET name="Child" cascade="all" lazy="true">
<KEY column="ClientID" />
<MANY-TO-ONE name="Client" class="SocksCDS.Client, SocksCDS" column="ClientID"/>
</SET>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Configuration cfg = new Configuration();
cfg.AddAssembly("SocksCDS");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
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.Ssn = txtClientSSN.Text;
newClient.City = txtClientCity.Text;
newClient.ClientMI = txtMI.Text;
newClient.MaritalStatus = comboMaritalStatus.Text;
newClient.ApplicationDate = txtApplicationDate.Text;
session.Save(newClient);
transaction.Commit();
session.Close();
Full stack trace of any exception that occurs:Code:
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.TypeInitializationException: The type initializer for 'NHibernate.Cfg.Configuration' threw an exception. ---> System.TypeInitializationException: The type initializer for 'log4net.Core.LoggerManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'log4net.Util.LogLog' threw an exception. ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section hibernate-configuration. (E:\Documents and Settings\George\My Documents\Visual Studio 2005\Projects\Socks CDS\bin\Debug\Socks CDS.exe.config line 9)
at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
--- End of inner exception stack trace ---
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
at System.Diagnostics.TraceInternal.InitializeSettings()
at System.Diagnostics.TraceInternal.WriteLine(String message)
at System.Diagnostics.Trace.WriteLine(String message)
at log4net.Util.LogLog.Error(String message, Exception exception)
at log4net.Util.LogLog..cctor()
--- End of inner exception stack trace ---
at log4net.Util.LogLog.Debug(String message)
at log4net.Core.LoggerManager..cctor()
--- End of inner exception stack trace ---
at log4net.Core.LoggerManager.GetLogger(Assembly repositoryAssembly, String name)
at log4net.LogManager.GetLogger(Type type)
at NHibernate.Cfg.Configuration..cctor()
--- End of inner exception stack trace ---
at NHibernate.Cfg.Configuration..ctor()
at SocksCDS.Form2.btnSaveClientInformation_Click(Object sender, EventArgs e) in E:\Documents and Settings\George\My Documents\Visual Studio 2005\Projects\Socks CDS\Form2.cs:line 98
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.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
----------------------------------------
Socks CDS
Assembly Version: 0.0.1.1
Win32 Version: 0.0.1.1
CodeBase: file:///E:/Documents%20and%20Settings/George/My%20Documents/Visual%20Studio%202005/Projects/Socks%20CDS/bin/Debug/Socks%20CDS.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_MSIL/System.Configuration/2.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Xml
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_MSIL/System.Xml/2.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
NHibernate
Assembly Version: 1.0.4.0
Win32 Version: 1.0.4.0
CodeBase: file:///E:/Documents%20and%20Settings/George/My%20Documents/Visual%20Studio%202005/Projects/Socks%20CDS/bin/Debug/NHibernate.DLL
----------------------------------------
SocksCDS
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///E:/Documents%20and%20Settings/George/My%20Documents/Visual%20Studio%202005/Projects/Socks%20CDS/bin/Debug/SocksCDS.DLL
----------------------------------------
System.Data
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.42 (RTM.050727-4200)
CodeBase: file:///E:/WINDOWS/assembly/GAC_32/System.Data/2.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
log4net
Assembly Version: 1.2.9.0
Win32 Version: 1.2.9.0
CodeBase: file:///E:/Documents%20and%20Settings/George/My%20Documents/Visual%20Studio%202005/Projects/Socks%20CDS/bin/Debug/log4net.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
Name and version of the database you are using:Access 2003
Here is the app.config file and the hibernate.cfg.xml file as well:
app.config
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0">
<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=E:\Socks\Database\SocksCDS.mdb</property>
<!-- mapping files -->
<mapping resource="Client.hbm.xml" assembly="SocksCDS.Client" />
<mapping resource="Child.hbm.xml" assembly="SocksCDS.Child" />
<mapping resource="Spouse.hbm.xml" assembly="SocksCDS.Spouse" />
<mapping resource="Employer.hbm.xml" assembly="SocksCDS.Employer" />
<mapping resource="Assistance.hbm.xml" assembly="SocksCDS.Assistance" />
<mapping resource="Wages.hbm.xml" assembly="SocksCDS.Wages" />
</session-factory>
</hibernate-configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section
name="nhibernate"
type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.0" >
<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=E:\Socks\Database\SocksCDS.mdb</property>
<!-- mapping files -->
<mapping resource="Client.hbm.xml" assembly="SocksCDS.Client" />
<mapping resource="Child.hbm.xml" assembly="SocksCDS.Child" />
<mapping resource="Spouse.hbm.xml" assembly="SocksCDS.Spouse" />
<mapping resource="Employer.hbm.xml" assembly="SocksCDS.Employer" />
<mapping resource="Assistance.hbm.xml" assembly="SocksCDS.Assistance" />
<mapping resource="Wages.hbm.xml" assembly="SocksCDS.Wages" />
</session-factory>
</hibernate-configuration>
</configuration>
The classes that these map to are wrapped up in a .dll called SocksCDS.dll.
Any help is appreciated : I'm certain that I've screwed up somewhere, I'm just not sure where.
Here's what the database itself looks like, relationship wise.
Again, any help is appreciated. Should you need me to post the classes, I can do that as well.[/img]