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.  [ 8 posts ] 
Author Message
 Post subject: NHibernate on Mono/Linux -- XmlSchema error reading config
PostPosted: Fri Sep 14, 2007 12:45 am 
Newbie

Joined: Thu Sep 13, 2007 9:17 pm
Posts: 3
Hi

Does anyone here use NHibernate under Mono? I've encountering an obscure error with even the simplest attempts. It seems to attempt validate my config file against some schema and fails.

==============================================================
Code:
using NHibernate;
using NHibernate.Cfg;

public class NhThing {

    public static void Main(string[] args) {
        NhThing nhThing = new NhThing();
    }

    public NhThing() {
        Configuration cfg = new Configuration();
        ISessionFactory sessionFactory = cfg.Configure().BuildSessionFactory();
     
    }
}

==============================================================
Code:
Unhandled Exception: NHibernate.HibernateException: problem parsing configuration : System.Xml.Schema.XmlSchemaValidationException: XmlSchema error: Element declaration for configuration is missing. XML URI: file:///home/steve/tmp/NHThing/build/hibernate.cfg.xml . Line 2, Position 2.
  at System.Xml.XmlValidatingReader.OnValidationEvent (System.Object o, System.Xml.Schema.ValidationEventArgs e) [0x00000]
  at (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_object_ValidationEventArgs (object,System.Xml.Schema.ValidationEventArgs)
  at Mono.Xml.Schema.XsdValidatingReader.HandleError (System.Xml.Schema.XmlSchemaValidationException schemaException, Boolean isWarning) [0x00000]
  at Mono.Xml.Schema.XsdValidatingReader.HandleError (System.String error, System.Exception innerException, Boolean isWarning) [0x00000]
  at Mono.Xml.Schema.XsdValidatingReader.HandleError (System.String error, System.Exception innerException) [0x00000]
  at Mono.Xml.Schema.XsdValidatingReader.HandleError (System.String error) [0x00000]
  at Mono.Xml.Schema.XsdValidatingReader.AssessStartElementSchemaValidity () [0x00000]
  at Mono.Xml.Schema.XsdValidatingReader.Read () [0x00000]
  at System.Xml.XmlValidatingReader.Read () [0x00000]
  at System.Xml.XmlDocument.ReadNodeCore (System.Xml.XmlReader reader) [0x00000]
  at System.Xml.XmlDocument.ReadNode (System.Xml.XmlReader reader) [0x00000]
  at System.Xml.XmlDocument.Load (System.Xml.XmlReader xmlReader) [0x00000]
  at NHibernate.Cfg.Configuration.Configure (System.Xml.XmlTextReader reader) [0x00000]
  at NHibernate.Cfg.Configuration.Configure (System.Xml.XmlTextReader reader) [0x00000]
  at NHibernate.Cfg.Configuration.Configure (System.String resource) [0x00000]
  at NHibernate.Cfg.Configuration.Configure () [0x00000]
  at NhThing..ctor () [0x00000]
  at NhThing.Main (System.String[] args) [0x00000]

==============================================================
hibernate.cfg.xml
==============================================================
Code:
<?xml version="1.0" ?>
<configuration>
   <configSections>
       <section
           name="nhibernate"
           type="System.Configuration.NameValueSectionHandler,
System, Version=1.0.5000.0,Culture=neutral,
PublicKeyToken=b77a5c561934e089"
       />
   </configSections>
   <nhibernate>
       <add
           key="hibernate.connection.provider"
           value="NHibernate.Connection.DriverConnectionProvider"
       />
       <add
           key="hibernate.connection.driver_class"
           value="NHibernate.Driver.MySqlDataDriver"
       />
       <add
           key="hibernate.connection.connection_string"
value="Server=localhost;Database=hvhs_account_manager_test;UserID=dev;Password=;"
       />
       <add
           key="hibernate.dialect"
           value="NHibernate.Dialect.MySQLDialect"
       />

   </nhibernate>

</configuration>


Top
 Profile  
 
 Post subject: Use NHibernate Config Section Handler
PostPosted: Fri Sep 14, 2007 8:41 am 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
Try using the NHibernate config section handler (NHibernate.Cfg.ConfigurationSectionHandler) as follows (same goes for log4net if you wanted to use it).

Code:
  <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.driver_class">NHibernate.Driver.OracleDataClientDriver</property>
       <property name="dialect">NHibernate.Dialect.OracleDialect</property>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
      <!-- providerName="System.Data.OracleClient" -->
      <property name="connection.connection_string">Data Source=MYDB;User ID=theguy;Password=blahblahblah;Unicode=True</property>
      <property name="connection.isolation">ReadCommitted</property>

      <mapping assembly="My.Library" />
    </session-factory>
  </hibernate-configuration>

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject: Re: Use NHibernate Config Section Handler
PostPosted: Fri Sep 14, 2007 9:19 am 
Newbie

Joined: Thu Sep 13, 2007 9:17 pm
Posts: 3
jlockwood wrote:
Try using the NHibernate config section handler (NHibernate.Cfg.ConfigurationSectionHandler) as follows (same goes for log4net if you wanted to use it).


Firstly, thanks greatly for responding! :)

Well, the problem I'm having is that it throws an exception while trying to even read the config file. The validating reader complains that the elements (regardless of what I try to use) are undeclared.

It seems that either, there's a very fundamental bug somewhere, or there's something amiss in the way NHibernate gets its xml schemas for validation. I see relevent looking xsd files in the source, but I'm unclear on how they're specified at runtime. Are there supposed to be xsd files in my project somewhere? Are they in some assembly?

Something very basic is broken here.


Top
 Profile  
 
 Post subject: Re: Use NHibernate Config Section Handler
PostPosted: Fri Sep 14, 2007 12:00 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
No xsds nee to be with your build output. The xsd is in the NHibernate project and should have been compiled as an embedded resource. If you built from source you might want to look there and make sure that embedded resources are being treated properly. NHibernate binary should be getting the xsd through the assembly manifest.
filename: nhibernate-configuration.xsd (in project root)

There's also:
nhibernate-mapping.xsd
nhibernate-generic.xsd

I'm' not sure off hand if you could drop the xsds in the bin and have it work as a quicky.

As far as config section itself, xml namespace is specified in the config section so section format must conform to schema.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 14, 2007 12:27 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
You are formatting your hibernate.cfg.xml as though it were a .config file. See here for the proper format.


Top
 Profile  
 
 Post subject: Ooops
PostPosted: Fri Sep 14, 2007 1:30 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
marcal wrote:
You are formatting your hibernate.cfg.xml as though it were a .config file. See here for the proper format.


You are absolutely correct, this is what I meant to post.
Here's a config file from a sample access project.
Code:
<?xml version="1.0" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.2" >
  <session-factory>
    <property name="hibernate.connection.release_mode">on_close</property>
   
    <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=C:\Sample.mdb</property>
  </session-factory>
</hibernate-configuration>

Same content, really. You just don't use the config settings. Bottom line, NHibernate expectes your config sections to conform to the appropriate schema, in my case: nhibernate-configuration-2.2.

(sjfloat) What version are you using?

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


Top
 Profile  
 
 Post subject: Awkward and grateful
PostPosted: Fri Sep 14, 2007 2:35 pm 
Newbie

Joined: Thu Sep 13, 2007 9:17 pm
Posts: 3
Quote:
Same content, really. You just don't use the config settings. Bottom line, NHibernate expectes your config sections to conform to the appropriate schema, in my case: nhibernate-configuration-2.2.


Well, I don't know what to say. I could *swear* I tried that very thing at least a dozen times -- including the switching of the '2.2' to '2.0' (mine's 2.0) and back, and everything else I could think of.

But, yes. Now it parses the file just fine.

Thanks so much for taking the time to help me with this!


Top
 Profile  
 
 Post subject: Re: Awkward and grateful
PostPosted: Fri Sep 14, 2007 2:39 pm 
Regular
Regular

Joined: Fri Jan 20, 2006 7:45 pm
Posts: 97
Location: San Antonio, TX
sjfloat wrote:
Quote:
Same content, really. You just don't use the config settings. Bottom line, NHibernate expectes your config sections to conform to the appropriate schema, in my case: nhibernate-configuration-2.2.


Well, I don't know what to say. I could *swear* I tried that very thing at least a dozen times -- including the switching of the '2.2' to '2.0' (mine's 2.0) and back, and everything else I could think of.

But, yes. Now it parses the file just fine.

Thanks so much for taking the time to help me with this!


No problem bro, been there myself.

_________________
Dum spiro, spero
-------------------------------
Rate my post if it helps...


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