-->
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.  [ 4 posts ] 
Author Message
 Post subject: Multiple <session-factory> instances in hibernate.cfg.
PostPosted: Fri Dec 10, 2004 3:06 pm 
Newbie

Joined: Wed Dec 08, 2004 5:59 pm
Posts: 3
Location: Detroit, MI
Hibernate version: 2.1.7

Perhaps I'm reading the documentation incorrectly, but I'm having trouble configuring my application to have more than one SessionFactory. It seems as though there is a contradiction between what's in the documentation and what's in the DTD.

In the DTD (http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd), the comment at the top of the file says "... a number of SessionFactory instances to be listed in JNDI ...". But the DTD describes the hibernate-configuration element as

Code:
<!ELEMENT hibernate-configuration (session-factory)>

Which I believe means that only one element of session-factory is expected.

How can you configure multiple session factories in the hibernate.cfg.xml file?

FYI - I've tried code like:

Code:
<hibernate-configuration>
    <session-factory name="java:comp/env/hibernate/SFOne">

        <!-- direct JDBC connection properties -->

        <!-- mapping files -->
        <mapping resource="com/fsb/DocumentType.hbm.xml" />
        <mapping resource="com/fsb/Document.hbm.xml" />

    </session-factory>
    <session-factory name="java:comp/env/hibernate/SFTwo">

        <!-- direct JDBC connection properties -->

        <!-- mapping files -->
        <mapping resource="com/fsb/Code.hbm.xml" />

    </session-factory>
</hibernate-configuration>

but get the following exception when running my JUnit tests:

Full stack trace of any exception that occurs:
Error parsing XML: /hibernate.cfg.xml(45) The content of element type "hibernate-configuration" must match "(session-factory)".

I'm pretty sure I can see how it would be done programmatically, but I'd be interested in knowing if there is a way to do it using something built into the configuration file.

Interestingly enough, Gavin, you said you were thinking about it back in 2002. (http://www.mail-archive.com/hibernate-devel@lists.sourceforge.net/msg00834.html) Did you get it done?

Joe


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 3:42 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you want to have multiple sessionfactories then you use multiple cfg files and use new Configuration().configure(cfgfileorresourcename)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: The DTD seems a bit misleading
PostPosted: Wed Apr 20, 2005 3:03 pm 
Newbie

Joined: Mon Jul 12, 2004 12:33 pm
Posts: 6
it states:

Code:
<!-- Hibernate file-based configuration document.

<!DOCTYPE hibernate-configuration PUBLIC
   "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

An instance of this document contains property settings and references
to mapping files for a number of SessionFactory instances to be listed
in JNDI.

-->


the phrase a "number" of SessionFactory instances suggests that more than one session-factory can be ina single hibernate.cfg.xml


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 20, 2005 3:54 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
but the DTD doesnt....typo in the comment i would assume

_________________
Max
Don't forget to rate


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