-->
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: Best Practice for mapping file placement?
PostPosted: Tue Oct 10, 2006 6:42 pm 
Newbie

Joined: Thu Oct 05, 2006 5:14 pm
Posts: 1
Hello,

I was hoping that someone could give me a little insight on this subject. I've been working with Hibernate 3.1.3 for a little while now, though not long enough to be fully aware of how to do everything, and I was looking for an answers to a question I have regarding alternate placement of cfg.xml and hbm.xml files in the directory structure of an application.

For example one has a hibernate.cfg.xml file and a persons.hbm.xml file. Typically hibernate.cfg.xml would be placed in the root level of the package structure (for instance ./classes), and persons.hbm.xml would reside next to its .class counterpart in the package structure whatever that may be.

My question is this: does Hibernate support configuration files, and mapping files in directories other than the default/expected ones? I am aware that I can place my configuration file (hibernate.cfg.xml) in a folder that is not the root path for all class packages, but can I place the mapping files in this directory as well, seperating them from the class files?

For example: hibernate.cfg.xml is placed in a ./conf/ directory, while all the classes are in their appropriate package structures underneath ./classes/ -- is it possible for me to place all of my xml files underneath the ./conf/ directory as well, rather than have them all under ./classes/?

Also, I should note that this seems to behave differently when running a web service (Axis-enabled within Tomcat which is running as a service) vs. running a client application on a desktop. I have been able to reference all of my configuration and mapping files underneath a ./conf/ directory while running an application, however I can only reference the configuration file in a seperate directory when running a web service. The only reasoning I can find for this is that the application seems to be launching from the System32 directory (probably because Tomcat is installed as a service).

I would like to place all my xml configuration and mapping files in a seperate directory structure under ./conf/ because it organizes everything together. If someone can give me a good argument as why not to do this, I am listening.

Regards,
Sean


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 19, 2007 7:36 am 
Newbie

Joined: Tue Jun 19, 2007 6:53 am
Posts: 7
Location: Hamburg, Germany
I also had this problem and after searching through many pages I finally found the solution in this thread: http://forum.hibernate.org/viewtopic.php?t=936082

The key is to change
Code:
<mapping resource="com/example/program/MyClass.hbm.xml"/>

to
Code:
<mapping file="config/MyClass.hbm.xml"/>


This way, you can separate your mapping files from your class files.

I use this to be able to clean my project via an ANT target (which deletes the bin folder where the mapping files have been) without the need to remember to generate the mapping files via another ANT target afterwards.


Hope this helps other people to more quickly find a solution. Perhaps, it could be pointed out in the documentation or FAQ? I searched these but didnĀ“t found it.


Lars


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.