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.  [ 5 posts ] 
Author Message
 Post subject: hibernate.cfg.xml as java object?!?
PostPosted: Tue Jul 31, 2007 9:08 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
Hi,

I want to know if it is possible to access the properties file as a java object. I just want to access the data saved in there on a easy way. What I'm exactly needing is url, username and passwort.

Ciao Carina

Hibernate version: 3.2.0 beta8


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 4:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
properties files can be accessed via Properties ;)

The other way is using Hibernate Configuration object, but not much different when it is those 3 pieces of information you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 4:40 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
I forgot to mention that I'm using the hibernate.cfg.xml file for saving all the connection properties. I tried to access it the way you told me, but I just got empty Properties. Could you perhaps give me a little code example or something in this way?!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 7:30 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
cfg.getProperty("blablah")

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 9:58 am 
Regular
Regular

Joined: Thu Apr 05, 2007 7:05 am
Posts: 53
Location: Troisdorf, Germany
For all with the same problem: My solution:

Code:
Properties prop = new Configuration().configure().getProperties();
DriverManager.getConnection(prop.getProperty("hibernate.connection.url"),
      prop.getProperty("hibernate.connection.username"),
      prop.getProperty("hibernate.connection.password"));


Thanks to all!


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