-->
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.  [ 6 posts ] 
Author Message
 Post subject: System property (-D) to change Hib. configuration file name
PostPosted: Sun Mar 26, 2006 9:58 am 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
Hi,

Is it possible to set some system/java property (java -Dproperty=value) to tell Hibernate to read configuration from another file than default hibernate.cfg.xml or hibernate.properties?

I know it could be done in runtime by Java code, but -D would be easier to switch between different configurations or choose stand alone/JBoss version.

I use Hibernate 3.1.2.

Thanks for help
Marcin


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 26, 2006 11:14 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
There's no property built into Hibernate to do that, but why not create your session factory as follows?

Code:
SessionFactory sf = new Configuration().configure(System.getProperty("hibernate.cfg_file_name", "hibernate.cfg.xml"));



That way it'll act as normal unless you override it with a property.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 3:16 pm 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
Thanks for your answer and sorry for a delay. I was away for a while.

r1ch wrote:
There's no property built into Hibernate to do that, but why not create your session factory as follows?

Code:
SessionFactory sf = new Configuration().configure(System.getProperty("hibernate.cfg_file_name", "hibernate.cfg.xml"));


That way it'll act as normal unless you override it with a property.


It looks good, but is it possible to use it in cooperation with JBoss?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 04, 2006 4:08 pm 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Surely it should work the same way with JBoss - or am I missing something?


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 1:02 pm 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
r1ch wrote:
Surely it should work the same way with JBoss - or am I missing something?

No, it was my temporary eclipse regarding fact how does JBoss fetch session factory.


Thanks again for your hint.
Marcin


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 12, 2006 10:02 am 
Newbie

Joined: Sun Mar 12, 2006 2:44 pm
Posts: 10
I wrote it too early.
In stand alone application I create SessionFactory once and take session using "getCurrentSession()" to perform "beginTransaction()" and it works properly.
In application started on JBoss I have:
Code:
tx = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");

and later "tx.begin()". In that case Hibernate is initialized with default parameters.

Is it possible to use similar trick in that situation?
Marcin


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