-->
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.  [ 3 posts ] 
Author Message
 Post subject: Best solution to have Hibernate load the mappings?
PostPosted: Fri Oct 06, 2006 8:18 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
Hibernate version:
3


Hello,

We have here an application splitted in several modules. Some of those modules provide beans along with their associated hibernate mapping file (a .hbm.xml in same package as the the class, with same name as the class).

However, maintenance problems arise when it comes to managing all those .hbm.xml.

Currently, in the final application, we have a
Code:
<mapping resource="x/y/Z.hbm.xml"/>
for each class hibernate has to support. It becomes very difficult to maintain as the web application grow, considering we have several developper configurations and a production configuration. We have regulary the problem of a missing mapping reference in the configuration file, when a developper added some beans but didn't update all the configuration files. And of course, until the app try to persist / load that specific bean, errors don't show

Is there some way to tell hibernate to automatically load the .hbm.xml files? If i don't reference the .hbm.xml files in the configuration file, hibernate throws "Unknown entity" exceptions. Why doesn't it try to load the .hbm.xml, considering docs tell us to put that with same name as class, with a .hbm.xml extension and in same package??

as a solution, i tried <mapping package="x.y"/>, considering package are far more stable in the time than their content. However, it doesn't load x.y.*.hbm.xml ?? what is mapping package for? I found no docs about it.

Also, i could use the .jar loading, but again there is no docs about this parameter and, because our module jar have a version number, we hit the same problem of new class, we have to keep the jar name updated each time a module version is modified?

What is the suggested way to handle the most easily all hibernate mappings in a web application?


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 8:28 am 
Senior
Senior

Joined: Tue Aug 23, 2005 8:52 am
Posts: 181
If you are using code to initialize the SessionFactory, you can use
Configuration.addDirectory(top-level-dir)
which will run through each of your directories and load all .hbm.xmls in it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 06, 2006 10:40 am 
Senior
Senior

Joined: Tue May 10, 2005 9:00 am
Posts: 125
The .hbm.xml file are in module jars, not in directory. The jar names are subject to change based on modules version, that's why i'd like to prevent the use of jar imports too.

Ideally, i would like to have some way for hibernate to scan my classpath for definitions, the same way things like JSF does to load configuration of modules. I don't have to provide JSF with the configuration file of all my modules, it automatically load them from the .jar. But i suppose no such behaviour is present in hibernate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.