Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Two hibernate.cfg.xml files?

 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Jane Jukowsky
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic