-->
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.  [ 3 posts ] 
Author Message
 Post subject: Possible to configure ONLY jdbc parms from properties file?
PostPosted: Thu Feb 21, 2008 12:18 pm 
Newbie

Joined: Wed Jan 10, 2007 9:33 am
Posts: 13
--

Hi. Is it possible to pull in only JDBC parameters from a properties file and reference them dynamically in a hibernate config xml file? I am trying to do something like this, where I have the hibernate.* values in a .properties file on my classpath:

Code:

<hibernate-configuration>
  <session-factory>
    <property name="hibernate.connection.url">${hibernate.connection.url}</property>
    <property name="hibernate.connection.driver_class">${hibernate.connection.driver_class}</property>
    <property name="hibernate.connection.username">${hibernate.connection.username}</property>
    <property name="hibernate.connection.password">${hibernate.connection.password}</property>
    <property name="hibernate.connection.pool_size">${hibernate.connection.pool_size}</property>

...

  </session-factory>
</hibernate-configuration>



I am getting a message that says:

Code:

10:55:43,444  WARN UserSuppliedConnectionProvider:23 - No connection properties specified - the user must supply JDBC connections



I know that you can reference system properties in this manner, but I wanted to know if it's possible get them from a secondary properties file. If what I am trying to do is possible, could you please provide me with the correct syntax? Thanks.

--


Top
 Profile  
 
 Post subject: Simple
PostPosted: Thu Feb 21, 2008 12:51 pm 
Newbie

Joined: Wed Jan 10, 2007 9:33 am
Posts: 13
I just needed to take out the connection properties in hibernate.cfg.xml, and then keep hibernate.properties in my classpath. This configuration picks up the connection parms from .properties file, and then pulls the rest of the information from the XML file.

I wonder if there is a way to rename hibernate.properties and then still be able to reference the values in the XML file somehow?

Guess this way is ok for now.

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 21, 2008 5:18 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
Remove the hibernate.connection properties from hibernate.cfg.xml file and add them to hibernate.properties. So when you configure Hibernate first time using like:

Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();


It will load the properties from hibernate.properties first then load the properties from hibernate.cfg.xml. So this way you can keep the database connection properties in your properties file.

Or else, you can give the configure the properties using Environment attributes with Configuration class in your code dynamically.


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