aspose file tools*
The moose likes Object Relational Mapping and the fly likes Two hibernate.cfg.xml files? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Two hibernate.cfg.xml files?" Watch "Two hibernate.cfg.xml files?" New topic
Author

Two hibernate.cfg.xml files?

Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
I have two applications, let's call them Small and Large. Small does not know anything about Large; Large is built on top of Small and has it in classpath. Both use hibernate: same user, same schema, same connection pool (when running within the same JVM), etc.

Is there any way to split hibernate.cfg.xml into two? small.cfg.xml for Small, small.cfg.xml + large.cfg.xml for large? How do I do that while still loading two cfg.xml's under the same Session and without a significant performance impact?

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


How do I do that while still loading two cfg.xml's under the same Session and without a significant performance impact?

Its a fairly small performance impact; OK you need to configure two SessionFactories for your application but it would be a one off operation.


I have two applications, let's call them Small and Large. Small does not know anything about Large; Large is built on top of Small and has it in classpath. Both use hibernate: same user, same schema, same connection pool (when running within the same JVM), etc.

Why split this? "large" sounds like a Hibernate layer that can be used by either application. Assuming each application has a data access layer can't you just expose this bits you need from this? What benefits are you hoping to git from doing this?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Why split this? "large" sounds like a Hibernate layer that can be used by either application. Assuming each application has a data access layer can't you just expose this bits you need from this?


Won't that requite Small to depend on Large then?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

It would require a shared dependency from both applications on a shared Hibernate layer, but this is a fairly common thing. It is after all the main reason why you create application layers. Is this a problem?
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
Paul Sturrock wrote:It would require a shared dependency from both applications on a shared Hibernate layer, but this is a fairly common thing. It is after all the main reason why you create application layers. Is this a problem?


Well, yes, such excessive coupling of disparate modules seems unnatural. When I ship Small, I want its data access layer encapsulated and not shared with the customer's. Let alone the pojo layer.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Disparate modules? You said your Hibernate code uses the same schema, is this not the case?

If you are trying to create a different view of a shared database why are you using the same schema? Is this not the problem the schema concept exists to solve?
Jane Jukowsky
Ranch Hand

Joined: Mar 28, 2009
Posts: 145
My bad. I am using separate schemas, same database, same user.

Still, problem still stands. I don't want my customers to mess up with my hibernate.cfg.xml, I want them to have their own. Besides, even if wanted them to do that, that would mean that my application in standalone mode would give me a bunch of ClassNotFounds, or similar, right? I mean, if the customer adds a bunch of mappings to classses that my standalone knows nothing about, my Hibernate in standalone mode won't initialize :-(
tabiul mahmood
Greenhorn

Joined: Sep 17, 2009
Posts: 18
I would suggest that you make the small project as a seperate jar and the add the jar as dependend for the bigger jar. No matter what you will need two hibernate.cfg.xml file as it is two different schema thus having their own username and password. By having different jar it will allow you to manage then two project sperately
 
jQuery in Action, 2nd edition
 
subject: Two hibernate.cfg.xml files?