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.  [ 13 posts ] 
Author Message
 Post subject: Problem with Config
PostPosted: Mon Nov 24, 2008 5:25 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hi Folks,
this is my next try to get a little Help:

I tried the Tutorial http://nhibernate.sourceforge.net/NHibernateEg/NHibernateEg.Tutorial1A.html#NHibernateEg.Tutorial1A-Configuration

In my App, the first step (NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();) throws an exception...

properties = Environment.Properties; (in Configuration.cs) throws an exception.

Why?
At this moment I could not do anything wrong, I think.

What could be the reason for this?

Please help me.....
For more Info, pls ask.

thanks Telefisch


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 6:23 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
one more question...

what does NHibernate load / check ore use, when executing "NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();"

I tried this in another new app without any configuration and it was successful.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 7:05 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Which exception ? Can you post your configuration file ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 7:14 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hi wolli,

with the above commented Tutorial I wanted to start NHibernate without a config-file.

I tried a second test-solution without any config and it worked fine.

I located the exception in the Configuration.cs of NHibernate.
The Exception in German is:

Der Typeninitialisierer für NHibernate.Cfg.Environment hat eine Ausnahme verursacht

System.TypeInitializationException

This is the Codesnippet, where the fault is thrown:

Code:
/// <summary>
      /// Clear the internal state of the <see cref="Configuration"/> object.
      /// </summary>
      protected void Reset()
      {
         classes = new Dictionary<string, PersistentClass>(); //new SequencedHashMap(); - to make NH-369 bug deterministic
         imports = new Dictionary<string, string>();
         collections = new Dictionary<string, NHibernate.Mapping.Collection>();
         tables = new Dictionary<string, Table>();
         namedQueries = new Dictionary<string, NamedQueryDefinition>();
         namedSqlQueries = new Dictionary<string, NamedSQLQueryDefinition>();
         sqlResultSetMappings = new Dictionary<string, ResultSetMappingDefinition>();
         secondPasses = new List<SecondPassCommand>();
         propertyReferences = new List<Mappings.PropertyReference>();
         filterDefinitions = new Dictionary<string, FilterDefinition>();
         interceptor = emptyInterceptor;

//In the next Line the Exception occurs
         properties = Environment.Properties;
         auxiliaryDatabaseObjects = new List<IAuxiliaryDatabaseObject>();
         sqlFunctions = new Dictionary<string, ISQLFunction>();
         mappingsQueue = new MappingsQueue();
         eventListeners = new EventListeners();
         typeDefs = new Dictionary<string, TypeDef>();
         extendsQueue = new HashedSet<ExtendsQueueEntry>();
         tableNameBinding = new Dictionary<string, Mappings.TableDescription>();
         columnNameBindingPerTable = new Dictionary<Table, Mappings.ColumnNames>();
      }


I've located the error but I dont know, where the Environment-variables are set...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 8:15 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I don't think that hibernate can be initialized without a configuration. You may use environment variables instead (never heard it before, but that doesn't mean much). But then I think you haven't set them appropriately.

I suppose your 2nd test solution did not contain any other classes with hibernate attributes. Probably as soon as hibernate tries to "parse" these attributes, you get that exception.

Have a look at that "first project":

http://nhforge.org/wikis/howtonh/your-first-nhibernate-based-application.aspx

It's newer and I think easier to understand.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 8:38 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
ok, if so,
what should I configure?
A dummy-database?

At this point, NHibernate does not know, where the working database is localized.
It also doesn't know which database-system the user will select...

So how can I create an Instance if the Database is not in the same Place I've fixed in the code?

...
I have found a better Exception-description:

"NHibernate.Cfg.Environment.BytecodeProvider" hat eine Ausnahme vom Typ "System.TypeInitializationException" verursacht.

And I tried this Example in my dll and in my Program as hibernate.cfg.xml without any change...


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 9:30 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
So, my last try:

My hibernate.cfg.xml:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
  <session-factory>
    <!--properties-->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="dialect">NHibernate.Dialect.MsSqlCeDialect</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlServerCeDriver</property>
    <property name="connection.connection_string">Data Source=Temp.sdf</property>
    <property name="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
    <!--Mappings-->
    <!--    <mapping resource="Solution.Mappings.Product.hbm.xml" assembly="Solution"/> -->
  </session-factory>
</hibernate-configuration>


then I added a Temp.sdf Database.

Then the only Class with Table-Informations, named "TempTbl.cs":
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DDT.PDMS.ProjektDatenbankFunktionen
{
    public class TempTbl
    {
        public virtual Guid Id
        {
            get;
            set;
        }
        public virtual string Name
        {
            get;
            set;
        }
    }
}


...and the corrsponding mappingfile, named "TempTbl.hbm.xml":
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="DDT.PDMS"
                   namespace="DDT.PDMS.ProjektDatenbankFunktionen">
  <class name="TempTbl">
    <id name="Id">
      <generator class="guid" />
    </id>
    <property name="Name" />
  </class>
</hibernate-mapping>


Are these files correct?
Do I need more?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 9:54 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You also have to register the mapping file somehow:

1) in the comfiguration file (like the one you have commented out)
2) cfg.AddFile(...)
3) cfg.AddAssembly("DDT.PDMS")

I suggest the last one, it's the easiest one. And don't forget to set the build action for the mapping file to "Embedded Resource".

Rest looks fine

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 10:11 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hmm...

I tried in the config file.

cfg.Add is not possible because the Error occurs before I could Add something, just when instatiating Configuration...

<mapping resource="DDT.PDMS.TempTbl.hbm.xml" assembly="DDT.PDMS"/>

and
<mapping resource="DDT.PDMS.ProjektDatenbankFunktionenTempTbl.hbm.xml" assembly="DDT.PDMS"/>

didn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 10:30 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Have you set the build action of hibernate.cfg.xml to "Embedded Resource" ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 24, 2008 11:04 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
In the Tutorial I should set the hbm file to Embedded.

I tried both, no success...

Now I deleted every Line of NHibernate in my code, deleted every reference and tried the Example again in my Application....

nothing.

I'm so sad !


Top
 Profile  
 
 Post subject: I did it !
PostPosted: Tue Nov 25, 2008 8:13 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 7:27 am
Posts: 26
Location: Germany
Hi Wolli,
I found the fault.

my app.config was buggie, don't know why...
NHibernate was not able to load the applications environment and so it couldn't extend the Environmen Class...

If the coders had thrown exceptions, thrown by the System, I had found it within minutes. So it took me a week, but so what...

thanks for your help...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2008 8:19 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Glad you finally found it. I was running out of ideas ...

_________________
--Wolfgang


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