aspose file tools*
The moose likes Object Relational Mapping and the fly likes No more .hbm.xml files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "No more .hbm.xml files" Watch "No more .hbm.xml files" New topic
Author

No more .hbm.xml files

Fabrizio Gianneschi
Ranch Hand

Joined: Nov 29, 2001
Posts: 70
Here's a question for Hibernate experts:

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
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
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
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
I'm use Hibernate extension tool for generate persistent with ant like this




And you can use XDoclet to generate persistent class ,So see detail at
http://www.hibernate.org/72.html


SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
Rickard Sundin
Greenhorn

Joined: Mar 10, 2003
Posts: 16
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
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
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
Or if you use the xml-style configuration file:
somkiat puisungnoen
Ranch Hand

Joined: Jul 04, 2003
Posts: 1312
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: No more .hbm.xml files