-->
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: Modular Hibernate configuration
PostPosted: Mon Mar 14, 2005 10:59 am 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
Hi, I'm migrating an application from EJB to Hibernate and I'm trying to keep the original architecture: the backend is decoupled from the frontend (servlet) and I'm using stateless EJB as façade. Also, the EJB are divided in different jar to keep the backend modular.

My question is: how should I configure Hibernate to access the mapping files contained in the different jars ? Is it possible to have multiple hibernate.cfg.xml files to keep the configuration modular ? Or should this be done programmatically ?

Any idea is welcome.

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 12:16 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
See Configuration.addResource(String) to specify individual mapping files (hbm.xml files) or Configuration.addClass(Class) to specify a class to map. (latter assumes that a mapping file named <ClassName>.hbm.xml exists in the same package directory as the specified class.) These methods look for the specified resources in your classpath, so multiple jars are fine.

You can also specify all mapping resources in your cfg.xml file. If you want to create multiple SessionFactory instances, use one cfg.xml per instance.

I suppose you could call Configuration.configure() multiple times, loading multiple cfg.xml files for one SessionFactory, but I'm not sure what that would do. However, there's nothing in the hibernate-configuration-3.0.dtd that says you couldn't create a mapping file with no properties and just references to mapping resources, effectively specifying a mapped "module" of hbm.xml files. Dunno. Check the source of Configuration.configure() before you try this. :)

From TFM: [url]file:///C:/hibernate/guide3.htm#session-configuration[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 1:57 pm 
Regular
Regular

Joined: Fri Sep 17, 2004 10:51 am
Posts: 61
Location: Rimini, Italy
What I currently have is a hibernate.property file for hibernate general configuration, and a hibernate.cfg.xml for object mapping.
I'm trying to use <mapping jar="" /> option to configure the ejb modules, but I've some problem with classloader (Hibernate can't find the configuration file).
Besides this, I'd like a pluggable configuration such that every module has it's own mapping configuration file.

_________________
--
Marco


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 14, 2005 2:45 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I assume that you're trying to load a cfg.xml file using <mapping jar="">, right?

As far as I can tell, the "jar" option on the mapping tag calls Configuration.addJar(), which reads all hbm.xml files from a jar. This will NOT read any cfg.xml files from the jar. (Check the source to confirm this...)

I'd figure the best way to do this is to continue what you're doing, as far as specifying all mapping resources for one "module" in a single cfg.xml file. Group related classes in jars (along with their mapping files) and load them using jar="". Make sure all jars are in the classpath. (This is the only potential non-modular part of the design.) When you want to load a "module" load the cfg.xml file programmatically using Configuration.configure().


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.