Is there a way to avoid populating the classpath (and source path) with .hbm.xml files?
I honestly prefer the "monolithic" configuration file approach, so can someone tell me why this practice is considered bad on Hibernate when defining the mappings?
Thanks in advance
Fabrizio Gianneschi<br />SCPJ2, SCWCD, SCBCD
Christian Bauer
author
Ranch Hand
Joined: Aug 31, 2004
Posts: 45
posted
0
It's common practice to use a file per persistent class (hierarchy), and some tools (middlegen, hbm2java) expect and generate this format only. If you don't follow it and have a single huge mapping file, you only have the disadvantages of maintaining that single file. I usually find it easier to seperate my mappings, even in small projects.
Co-Author of <a href="http://www.manning.com/bauer" target="_blank" rel="nofollow">Hibernate in Action</a>
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
have an ant task to generate your mapping files with xDoclet, put them in a jar, add only one file to the classpath.
pascal
MK Lee
Greenhorn
Joined: Jul 26, 2002
Posts: 5
posted
0
the hbm.xml is well-supported by the Hibernate Ext that comes along. I just need to write the hbm.xml file and build.xml then generate the java class & db script in no time.
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
posted
0
I'm use Hibernate extension tool for generate persistent with ant like this
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Rickard Sundin
Greenhorn
Joined: Mar 10, 2003
Posts: 16
posted
0
If you want to avoid clobbering your source code tree with a lot of hbm.xml-files, and also to avoid maintaining all hibernate configuration in a single file, try putting all mapping files (one per class) in a directory of their own. If you do that you will have to configure your SessionFactory with the names of the mapping files instead of the name of the classes.
/Rickard
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
posted
0
Originally posted by Rickard Johansson: If you want to avoid clobbering your source code tree with a lot of hbm.xml-files, and also to avoid maintaining all hibernate configuration in a single file, try putting all mapping files (one per class) in a directory of their own. If you do that you will have to configure your SessionFactory with the names of the mapping files instead of the name of the classes.
/Rickard
Do you have example to do that ?
Rickard Sundin
Greenhorn
Joined: Mar 10, 2003
Posts: 16
posted
0
Put the hbm.xml files in a directory 'mappings' (or whatever you like) in the root of your classpath.
/Rickard
Rickard Sundin
Greenhorn
Joined: Mar 10, 2003
Posts: 16
posted
0
Or if you use the xml-style configuration file:
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
posted
0
Originally posted by Rickard Johansson: Put the hbm.xml files in a directory 'mappings' (or whatever you like) in the root of your classpath.
/Rickard
or An alternative (sometimes better) way is to let Hibernate load a mapping file using getResourceAsStream():
Then Hibernate will look for mapping files named /org/hibernate/autcion/Item.hbm.xml and /org/hibernate/autcion/Bid.hbm.xml in the classpath. This approach eliminates any hardcoded filenames.