This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No more .hbm.xml files

 
Fabrizio Gianneschi
Ranch Hand
Posts: 70
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Christian Bauer
author
Ranch Hand
Posts: 45
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pascal betz
Ranch Hand
Posts: 547
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rickard Sundin
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put the hbm.xml files in a directory 'mappings' (or whatever you like) in the root of your classpath.



/Rickard
 
Rickard Sundin
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or if you use the xml-style configuration file:
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic