-->
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.  [ 6 posts ] 
Author Message
 Post subject: Nhibernate Library
PostPosted: Wed Jun 08, 2005 8:16 am 
Hello,
I'm working with Nhibernate via VS .NET 2003. I created a project and all operations works fine( Insertion, delete,select, update) And now i m trying to create a library which those functions, to call them from outside just by adding reference to MyLibrary.dll.

So i created a class test in another project and i added reference to MyLibrary.dll.

All show u an example with Insertion function :

Code:
using System;
using System.Collections;
using NUnit.Framework;
using NHibernate;
using NHibernate.Cfg;
using EquipMapLib;
//using ByteFX.Data.MySqlClient;
namespace EquipMapLib
{
   
   public class Insertion
   {
      
      public Insertion()
      {
      }

      

      public void InsertEquipement(Equipement Equip)
      {
             
         try
         {   
            
             Configuration cfg = new Configuration();
             Console.WriteLine("totototototototot");   
             cfg.AddAssembly("EquipMapLib");
             cfg.AddXmlFile("Equipement.hbm.xml");
             ISessionFactory factory = cfg.BuildSessionFactory();
             ISession session = factory.OpenSession();
              ITransaction transaction = session.BeginTransaction();
            
             session.Save(Equip);
              
             transaction.Commit();
           
             session.Close();
            
         }
         catch (System.Exception ex)
         {
            Console.WriteLine(ex.Message);
            throw ex;
         }
      }
      public void InsertEquipement2(int id,int local,string nom,string modele,string marque,string noserie,string commentaire,string description,string snmp)
      {   
         Equipement Equip = new Equipement(id,nom, modele, marque, noserie, commentaire, description, snmp,local);
         InsertEquipement(Equip);
      
      }
   }
}


The test :

Code:
using System;
using System.Collections;

namespace EquipMapLib
{
   
   public class Test
   {
      public static void Main(string[] args)
      {
           try
         {     
                 int i=18;
               Equipement Equip = new Equipement(i,"toto","modele","Marque","noSerieie","Commentzire","Decriptiorkg","snmdk",45);
                Insertion insert = new Insertion();
                insert.InsertEquipement(Equip);                  
         }
         catch (System.Exception ex)
         {
            Console.WriteLine(ex.Message);
         }
      }
   }
}


I got the following errors :

Code:
log4net:ERROR DOMConfigurator: ConfigureFromXML called with null 'element' para
eter
totototototototot
The dialect was not set. Set the property hibernate.dialect.
The dialect was not set. Set the property hibernate.dialect.
Press any key to continue


and in debug mode :

[code]'DefaultDomain'


Top
  
 
 Post subject: notice
PostPosted: Wed Jun 08, 2005 8:34 am 
Actually what i noticed is that it can't read configuration file App.config so it does not generate the file Myclasse.exe.config in the folder bin/debug.

But when i put the file App.config in the same folder as the class Test (Main) and the mapping file in the same project too the program works but it's not what i want. What i want is two separated project (class library)
and project using it independantly

Regards


Top
  
 
 Post subject: Re: notice
PostPosted: Wed Jun 08, 2005 11:29 am 
Regular
Regular

Joined: Mon May 16, 2005 2:15 pm
Posts: 59
guest wrote:
Actually what i noticed is that it can't read configuration file App.config so it does not generate the file Myclasse.exe.config in the folder bin/debug.


I assume the project you have the app.config in isn't one that builds an .exe.

Use the following after build event in the project that has the app.config that you want to couple with the dll.

copy /Y "$(ProjectDir)App.config" "$(TargetDir)$(TargetFileName).config"

I assume you will only want to use this for testing, and when you deply your app you will put the config items into the EXE's config.

Another approach is to use a stand alone XML config file and specify it in code when you create your session factory. Although, I tried this and couldn't seem to get it to find the file. But, I am only building tests at this point, so it didn't matter to me.

BOb


Top
 Profile  
 
 Post subject: OK
PostPosted: Thu Jun 09, 2005 8:50 am 
Thank u very much for your reply. It was some thing like that cause i'm using nhibernate with webservices and i juste added the app.config content to Web.config of the webservice (in the balise configuration) and it was ok

regards


Top
  
 
 Post subject: Re: Nhibernate Library
PostPosted: Thu Jun 09, 2005 11:57 am 
Hibernate Team
Hibernate Team

Joined: Thu May 12, 2005 3:53 am
Posts: 4
I just would like to assure that you know that you should have only one, and only one sessionfactory per program?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 10, 2005 10:52 am 
Regular
Regular

Joined: Tue May 31, 2005 3:18 pm
Posts: 117
Location: Houston
Yes, creating the configuration and session factories are EXPENSIVE operations.

You definitely need to keep a static (or singleton) NHibernateManager class around that can hold that stuff for you. It can still be abstracted away from your business logic, by only referencing this class from your MyLibrary.dll


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