-->
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.  [ 15 posts ] 
Author Message
 Post subject: NHibernate-2.0.0 Beta1 and VB.Net in VS.Net2005 using MSSQL2
PostPosted: Wed Jul 09, 2008 5:00 pm 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
How to fix this problem?
Code:
NHibernate.MappingException was unhandled
  Message="Could not find schema information for the element 'urn:nhibernate-mapping-2.2:hibernate-mapping'."
  Source="NHibernate"


Here's my nhibernate.cfg.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
   <session-factory name="NHibernate.Test">
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <property name="connection.connection_string">
         Server=(local);initial catalog=master;Integrated Security=SSPI
      </property>
      <property name="adonet.batch_size">10</property>
      <property name="show_sql">false</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="use_outer_join">true</property>
      <property name="command_timeout">444</property>
      <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
   </session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 10, 2008 7:57 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Looks like a problem with one of your mapping files. Check if they are ok (well-formed, no empty lines at the beginning). Try to remove all mapping files and see if the error is still there.

If you can't find a problem there, post the code, where you build the session factory.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 9:44 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
I am using the source from this tutorial:
http://www.codeproject.com/KB/vb/nhiber ... 29823&fr=1

Using MSSQL2000 and MSSQL2005, I no longer get the above error but a different one:

Code:
NHibernate.MappingException was unhandled
  Message="Unknown entity class: WindowsApplication1.testcust"
  Source="NHibernate"
  StackTrace:
       at NHibernate.Impl.SessionFactoryImpl.GetPersister(Type theClass)
       at NHibernate.Impl.SessionImpl.GetClassPersister(Type theClass)
       at NHibernate.Impl.SessionImpl.GetPersister(Object obj)
       at NHibernate.Impl.SessionImpl.SaveWithGeneratedIdentifier(Object obj, CascadingAction action, Object anything)
       at NHibernate.Impl.SessionImpl.Save(Object obj)
       at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\WindowsApplication1\Form1.vb:line 25
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.PerformClick()
       at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
       at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
       at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
       at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
       at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FPreTranslateMessage(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(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       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()


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 11, 2008 9:46 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
Here is my Form1.vb file. I can view the properties of the testcust object
on line 25 but I still get the error.
{All the other files are exactly the same as in the article with the exception that I'm using MSSQL2005 dialect instead of MSSQL2000 dialect and changing the DB name in the app.config and testcust.hbm.xml to master}

Code:
Imports NHibernate
Imports NHibernate.Cfg
Imports log4net
Imports System.Configuration
Imports NHibernate.Connection
Imports Iesi.Collections

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click

        Dim myConfig As New Configuration
        myConfig.AddAssembly("WindowsApplication1")
        myConfig.SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect")

        Dim myFactory As ISessionFactory = myConfig.BuildSessionFactory
        Dim mySession As ISession = myFactory.OpenSession
        Dim myTransaction As ITransaction = mySession.BeginTransaction

        Dim cust As New testcust
        cust.eno = TextBox1.Text
        cust.ename = TextBox2.Text
        cust.salary = TextBox3.Text

        mySession.Save(cust) ' line 25 is here
        myTransaction.Commit()
        mySession.Close()

        MsgBox("success")
    End Sub
End Class


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 9:49 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
Anyone else know about this?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 10:02 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
12. Make sure that “testcust.hbm.xml” file's property of Build Action is selected as Embedded Resources (default is none or compile). You may get Mapping Exception of entity or class due to this, if not selected.


Have you done this ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 10:12 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you find something like this in your log file ?

Quote:
2008-07-15 15:54:52,806 [1] INFO NHibernate.Cfg.Environment [(null)] <(null)> - NHibernate 1.2.1.4000 (1.2.1.4000)
2008-07-15 15:54:52,812 [1] INFO NHibernate.Cfg.Environment [(null)] <(null)> - nhibernate section not found in application configuration file
2008-07-15 15:54:52,813 [1] INFO NHibernate.Cfg.Environment [(null)] <(null)> - Bytecode provider name : lcg
2008-07-15 15:54:52,814 [1] INFO NHibernate.Cfg.Environment [(null)] <(null)> - Using reflection optimizer
2008-07-15 15:54:52,836 [1] INFO NHibernate.Cfg.Configuration [(null)] <(null)> - Searching for mapped documents in assembly: xyz
2008-07-15 15:54:52,838 [1] INFO NHibernate.Cfg.Configuration [(null)] <(null)> - Mapping resource: xyz.hbm.xml

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 10:36 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
Yes, it is embedded, where is that log file?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 10:47 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Depends on your log4net configuration. Since the example you mentioned has logging basically enabled, change the log4net section in your App.config to this:

Code:
<log4net debug="false">
    <appender name="console" type="log4net.Appender.ConsoleAppender, log4net">

      <layout type="log4net.Layout.PatternLayout">
        <!-- Pattern to output the caller's file name and line number -->
        <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
      </layout>
    </appender>

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


And you should see it in the output window. You may also use DEBUG instead of INFO but then you get lots of lines ...

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 10:51 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Sorry, there're two things missing which are necessary for log4net:

1) put XmlConfigurator.Configure() at the beginning of Sub Button1_Click

2) Add the log4net config section to your app.config:

Code:
  <configSections>
...
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" />
...
  </configSections>


If you have problems with the logging, have a look here:
[url]
http://blogs.hibernatingrhinos.com/nhib ... rnate.aspx[/url]

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 15, 2008 11:14 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
I do not have log4net configured in this app.config


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 2:10 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
"Here's my nhibernate.cfg.xml"


Looks like you have another difference to that sample project. Found it in your first post. Sorry, missed that earlier ...

The name must be hibernate.cfg.xml not nhibernate.cfg.xml. And I think this one must be set to "Embedded Resource".

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 9:19 am 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
Well, I, for some reason, can't find that file I mentioned in my original post.
However, when this line is run:

I check the values and both the CFGSchemaXMLNS and MappingSchemaXMLNS values are urn:nhibernate-configuration-2.0


Let me start over and see if I can figure it out. I will keep this thread open in case I have more or different problems.
Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 16, 2008 9:22 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
OK ... if you can't get it to work, send me an email and attach your project.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 18, 2008 1:20 pm 
Newbie

Joined: Thu Jul 03, 2008 1:03 pm
Posts: 11
Ok, the project is on it's way.


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