-->
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.  [ 2 posts ] 
Author Message
 Post subject: Dynamically load "Person.hbm.xml"?
PostPosted: Thu Apr 02, 2009 9:57 pm 
Beginner
Beginner

Joined: Mon Jan 05, 2009 7:08 am
Posts: 24
Hello

How can I dynamically load "Person.hbm.xml"? Reason I need to do this is, M$SQL Server supports IDENTITY, Oracle needs to use SEQUENCE. So the "Id" column would be different when switching the application from M$SQL to Oracle at run-time/on-the-fly.

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                            assembly="Util"
                            namespace="Util"
                            >
   <class name="Person" table="Person">
      <id name="Id" column="Id" type="Int64" unsaved-value="0">
         <generator class="native" />
      </id>
       ...
      </class>
...
</hibernate>


When swtiched from M$SQL (Id=IDENTITY) to Oracle (SEQUENCE=PERSON_SEQ)
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                            assembly="Util"
                            namespace="Util"
                            >
   <class name="Person" table="Person">
      <id name="Id" column="Id" type="Int64" unsaved-value="0">
         <generator class="sequence">
                             <param name="sequence">PERSON_SEQ</param>
                       </generator>
      </id>
       ...
      </class>
...
</hibernate>


The problem is "Person.hbm.xml" is loaded as "Embeded Resource"


REF 1: generator=sequence
http://www.hibernate.org/hib_docs/nhibe ... pings.html

REF 2: Startup loading code.
Code:
Configuration cfgPrimary = new Configuration();         cfgPrimary.Configure(".\\Resources\\nhibernate\\ThinkFundamentals.hibernate.cfg.xml");
cfgPrimary.AddClass(typeof(Util.Person));
ISessionFactory oNHFactoryPrimary = cfgPrimary.BuildSessionFactory();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 03, 2009 3:45 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Try:

cfgPrimary.AddFile(..)

_________________
--Wolfgang


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