-->
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 configuration files
PostPosted: Mon Jul 20, 2009 6:31 pm 
Newbie

Joined: Mon Jul 20, 2009 6:17 pm
Posts: 5
I have this configuration file, and it works fine but i want that the jdbc properties will be in a file. How can I do this?

hibernate.cfg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>

   <session-factory>

      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.url">jdbc:mysql://localhost:8081/mydatabase</property>
      <property name="connection.username">username</property>
      <property name="connection.password">password</property>
      
      <!-- SQL dialect -->
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!-- Echo all executed SQL to stdout -->
      <property name="show_sql">true</property>

      <mapping class="com.Person" />

   </session-factory>

</hibernate-configuration>


I want to have something like a jdbc.properties which is used on the hibernate.cfg.xml:
Code:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:8081/mydatabase
jdbc.username=username
jdbc.password=password
hibernate.dialect=org.hibernate.dialect.MySQLDialect


Thanks


Top
 Profile  
 
 Post subject: Re: Hibernate configuration files
PostPosted: Mon Jul 20, 2009 6:39 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
by default, Hibernate will read hibernate.properties.
Other way is calling configuration.addProperties(Properties)


Top
 Profile  
 
 Post subject: Re: Hibernate configuration files
PostPosted: Mon Jul 20, 2009 7:03 pm 
Newbie

Joined: Mon Jul 20, 2009 6:17 pm
Posts: 5
I put this on my hibernate.cfg.xml
Code:
      <property name="connection.driver_class">${jdbc.driverClassName}</property>
      <property name="connection.url">${jdbc.url}</property>
      <property name="connection.username">${jdbc.username}</property>
      <property name="connection.password">${jdbc.password}</property>


and create a hibernate.properties with this:
Code:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:8081/mydatabase
jdbc.username=username
jdbc.password=password
hibernate.dialect=org.hibernate.dialect.MySQLDialect


but i didn't work.

Thanks for your help


Top
 Profile  
 
 Post subject: Re: Hibernate configuration files
PostPosted: Mon Jul 20, 2009 8:39 pm 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
You can use either hibernate.cfg.xml or hibernate.properties.

if you want to use hibernate.properties
Code:
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:8081/mydatabase


ecar26 wrote:
I put this on my hibernate.cfg.xml
Code:
      <property name="connection.driver_class">${jdbc.driverClassName}</property>
      <property name="connection.url">${jdbc.url}</property>
      <property name="connection.username">${jdbc.username}</property>
      <property name="connection.password">${jdbc.password}</property>


and create a hibernate.properties with this:
Code:
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:8081/mydatabase
jdbc.username=username
jdbc.password=password
hibernate.dialect=org.hibernate.dialect.MySQLDialect


but i didn't work.

Thanks for your help


Top
 Profile  
 
 Post subject: Re: Hibernate configuration files
PostPosted: Tue Jul 21, 2009 9:53 am 
Newbie

Joined: Mon Jul 20, 2009 6:17 pm
Posts: 5
Oh, I understand now.

Thank you very much. :)


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.