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: How to map a directory and not concrete cfg.xml file.
PostPosted: Thu Nov 08, 2007 11:37 am 
Newbie

Joined: Thu Nov 08, 2007 11:28 am
Posts: 5
Hi,

I have a configuration xml file, from which my SessionFactory is configured.

I need something like:

Code:
<mapping resource="hibernate/mappings/Entity.hbm.xml"/>


but to map a directory not a concrete file.

With java code it is possible, but I want to know, if this is possible in xml configuration file, because I don't want to spread configuration all over the code, but to have it in one place. I need this, because my cfg.xml files are dinamicly created?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 12:06 pm 
Newbie

Joined: Wed Nov 07, 2007 7:12 am
Posts: 4
vb.net: you can try this in the nhibernatehelper class or when you configure your session factory:

Code:
Imports System
Imports System.Web
Imports NHibernate
Imports NHibernate.Cfg

Namespace NHWebSite
    Public NotInheritable Class NHibernateHelper

        Public Const CurrentSessionKey As String = "nhibernate.current_session"
        Public Shared ReadOnly sessionFactory As ISessionFactory

        Shared Sub New()
            Dim x As New NHibernate.Cfg.Configuration
            x.AddDirectory(yourdir)
            sessionFactory = x.Configure.BuildSessionFactory()
        End Sub

...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 08, 2007 12:10 pm 
Newbie

Joined: Thu Nov 08, 2007 11:28 am
Posts: 5
Tanks for your reply :)

I know, that it is possible to do this in code, but I want to have all configuration in the configuration file. I don't want to have parts of configuration in different places. Most of the configurations can be done in code and in xml file. But it seems, that this one can not be done in xml file!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 4:55 am 
Newbie

Joined: Wed Nov 07, 2007 7:12 am
Posts: 4
Yes, it's true, I understand your problem.
The way I do that is putting this row in the config file:

Code:
      <mapping assembly="NHWebSite" />


"NHWebSite" is the name of my project and the namespace of my entities and classes.
Code:
...
Namespace NHWebSite
    Public NotInheritable Class NHibernateHelper
...


In this way, when I create new entities and xml files in this namespace, I don't need to touch the config file.
I don't know if <mapping directory="" /> is allowed, Have you tried this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 6:38 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Another option is to provide a configuration item to your application that contains a path and your application can get the contents of the directory and add each found mapping file to the NHibernate configuration in code.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 09, 2007 12:26 pm 
Newbie

Joined: Thu Nov 08, 2007 11:28 am
Posts: 5
I am sorry, but I saw now, that I posted a topic in the wrong forum. This is a question for Hibernate, not NHibernate.

Sorry again!


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.