-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate.cfg.xml resides in an ear file? Can I modify it?
PostPosted: Fri Jun 09, 2006 11:54 am 
Newbie

Joined: Thu Mar 16, 2006 1:12 pm
Posts: 10
Hello all,

I'm using Hibernate 3.0.

I have a J2EE application - it's a ear file (containing a war and a jar). The hibernate.cfg.xml file is located inside the ear. The problem is that our application is supposed to work with multiple databases - meaning multiple dialects and different database connection parameters - which is specified inside the hibernate.cfg.xml file inside the ear. We don't want to have to "blow up" our ear file, modify the hibernate.cfg.xml file every time we want to use a different dialect (and different database connection parameters). And we don't want to have to build a different ear file (really the same ear file - but containing a custom hibernate.cfg.xml file) for every db.

Our application DOES use an external xml-based config file. We'd love to put these hibernate options inside THAT file. Is there anything we can do to keep our ear file "hermetically sealed" for your sanitation? Can we make hibernate look for "dialect", "connection.driver_class". etc. - somewhere besides the hibernate.cgf.xml file?

Thanks!

-john


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 5:27 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
Read the Javadoc for org.hibernate.cfg.Environment class. It may have what you need.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 10, 2006 11:25 am 
Newbie

Joined: Sat Mar 18, 2006 1:13 am
Posts: 10
We had a similar need. Effectively, we had username/pwd settings in a separate config file and didn't want them to be redundant in the hibernate.cfg.xml.

To accomplish this, it looks something like:

Configuration cfg = new Configuration().configure(<hibernate.cfg.xml>);

cfg.setProperty("connection.url", ...);
cfg.setProperty("connection.username", ...);
cfg.setProperty("connection.password", ...);

cfg.setProperty("hibernate.connection.url", cfg.getProperty("connection.url"));
cfg.setProperty("hibernate.connection.username", cfg.getProperty("connection.username"));
cfg.setProperty("hibernate.connection.password", cfg.getProperty("connection.password"));

hibernateSessionFactory = cfg.buildSessionFactory();

-----------------------

The trick is in knowing what properties need to be set.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 11, 2006 4:03 pm 
Regular
Regular

Joined: Mon Jun 13, 2005 12:21 pm
Posts: 61
Location: Hannover
If you've got an application server, isn't a JNDI based SessionFactor an option? We're using JNDI based datasource for running applications on multiple servers, our only problem is setting the correct dialect.


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