-->
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: How to centralize Hibernate and c3pO configuration ?
PostPosted: Thu Jan 08, 2009 5:52 am 
Newbie

Joined: Thu Jan 08, 2009 4:56 am
Posts: 5
Hi,


I have a little problem with hibernate and c3pO configuration.

I'm using JBoss 4.2.3/EJB3 and hibernate.

All is working fine, but the problem is I must set the login and password in the datasource (postgresql-ds.xml) and persistence.xml (for C3pO configuration) files.

So, each time I'm distributing my project I must re package the ear archive to include the modified persistence.xml file and I must set up the postgresql-ds.xml file...

So I would like to centralize the hibernate and c3pO configuration out of the ear file.

I was looking for but I didn't found anything.

This is my two configuration files.

postgresql-ds.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<datasources>
    <local-tx-datasource>
    <jndi-name>testDS</jndi-name>
    <connection-url>jdbc:postgresql://127.0.0.1:5432/database</connection-url>
    <driver-class>org.postgresql.Driver</driver-class>
    <user-name>username</user-name>
    <password>password</password>
    <!-- the minimum size of the connection pool -->
    <min-pool-size>1</min-pool-size>
    <!-- The maximum connections in a pool/sub-pool -->
     <max-pool-size>4</max-pool-size>
  </local-tx-datasource>
</datasources>


persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<persistence
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">

   <persistence-unit name="MetierPU">
      <jta-data-source>java:/testDS</jta-data-source>
      <properties>
         <property name="hibernate.hbm2ddl.auto" value="update" />

         <property name="hibernate.bytecode.use_reflection_optimizer" value="false" />
         
         <!-- propriétés OSCache -->
         <property name="hibernate.cache.provider_class" value="com.opensymphony.oscache.hibernate.OSCacheProvider" />
         <property name="hibernate.cache.use_query_cache" value="true" />
         <property name="hibernate.cache.use_second_level_cache" value="true" />
            

 
         <!-- propriétés DataSource c3p0 -->
         <property name="hibernate.connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider" />
         <property name="hibernate.c3p0.acquire_increment" value="1" />
         <property name="hibernate.c3p0.min_size" value="1" />
         <property name="hibernate.c3p0.max_size" value="10" />
         <property name="hibernate.c3p0.max_statements" value="0" />
         <property name="hibernate.c3p0.idle_test_period" value="0" />

         <!-- propriétés de connexion -->
         <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
         <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />


         <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/database" />
         <property name="hibernate.connection.username" value="username" />
         <property name="hibernate.connection.password" value="password" />
      </properties>
   </persistence-unit>
</persistence>



Thanks you for your help and advice.
I hope you understand what I mean.

regards,



Bal.


Hibernate version: 3.3.1
Name and version of the database you are using: postgresql 8.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 8:56 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
just write ur own configuration application by swing for ur application

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:39 am 
Newbie

Joined: Thu Jan 08, 2009 4:56 am
Posts: 5
Hi,

thanks for your answer.

Sorry but I don't understand what you mean.

I tried to replace login and password parameters with the following jndi.datasource option:

Code:
<property name="hibernate.connection.jndi.datasource" value="java:testDS" />


I'm getting this log, but c3pO doesn't succeed with connexion.

Code:
14:36:45,099 INFO  [hibernate.connection.ConnectionProviderFactory] Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider
14:36:45,108 INFO  [hibernate.connection.C3P0ConnectionProvider] C3P0 using driver: null at URL: null
14:36:45,109 INFO  [hibernate.connection.C3P0ConnectionProvider] Connection properties: {jndi.datasource=java:testDS, autocommit=true, release_mode=auto}
14:36:45,109 INFO  [hibernate.connection.C3P0ConnectionProvider] autocommit mode: true
14:36:45,109 WARN  [hibernate.connection.C3P0ConnectionProvider] No JDBC Driver class was specified by property hibernate.connection.driver_class
14:36:45,162 INFO  [v2.log.MLog] MLog clients using log4j logging.
14:36:45,785 INFO  [v2.c3p0.C3P0Registry] Initializing c3p0-0.9.1.2 [built 21-May-2007 15:04:56; debug? true; trace: 10]
14:36:45,925 INFO  [c3p0.impl.AbstractPoolBackedDataSource] Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@297bd5a1 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@39ce5024 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hge13g7y1emj9cbhsk98d|113727f, idleConnectionTestPeriod -> 0, initialPoolSize -> 1, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 10, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 1, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@34a3aa3d [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hge13g7y1emj9cbhsk98d|1441e32, jdbcUrl -> null, properties -> {jndi.datasource=java:testDS, autocommit=true, release_mode=auto} ], preferredTestQuery -> null, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hge13g7y1emj9cbhsk98d|19bf480, numHelperThreads -> 3 ]



We can see datasource is used by c3po, but it fails => "14:36:45,109 INFO [hibernate.connection.C3P0ConnectionProvider] Connection properties: {jndi.datasource=java:testDS, autocommit=true, release_mode=auto}"


Last edited by Baleyba on Thu Jan 08, 2009 9:48 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:41 am 
Regular
Regular

Joined: Wed Oct 15, 2008 6:59 am
Posts: 103
Location: Chennai
i mean write swing application to change ur configuration details whenever u r going to deploy ...

_________________
If u feel it will help you, don't forget to rate me....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 08, 2009 9:58 am 
Newbie

Joined: Thu Jan 08, 2009 4:56 am
Posts: 5
Ok thanks for that good idea. But it seems to be a big work for a little configuration problem I think.

But ideally, I would like to know if it is possible to allow c3po to catch directly jndi datasource configuration.

I think I'm not alone in this case.

regards,

Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 09, 2009 6:43 am 
Newbie

Joined: Thu Jan 08, 2009 4:56 am
Posts: 5
Hi,

I found a solution.

I just defined variables into a .properties file contained into the jboss conf/ directory.

So I re used this variables into the jndi datasource and into the persistence.xml files:


Datasource
Code:
<?xml version="1.0" encoding="UTF-8"?>

<datasources>
    <local-tx-datasource>
    <jndi-name>DefaultDS</jndi-name>
    <connection-url>${Url}</connection-url>
    <driver-class>${Driver}</driver-class>
    <user-name>${Login}</user-name>
    <password>${Password}</password>
    <!-- the minimum size of the connection pool -->
    <min-pool-size>1</min-pool-size>
    <!-- The maximum connections in a pool/sub-pool -->
     <max-pool-size>4</max-pool-size>

     <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml -->
     <metadata>
         <type-mapping>${Mapping}</type-mapping>
     </metadata>
  </local-tx-datasource>
</datasources>



Part of persistence.xml
Code:
<property name="hibernate.dialect" value="${Dialect}" />
         <property name="hibernate.connection.provider_class" value="${HibernateProvider}" />
         
         <property name="hibernate.connection.datasource" value="java:/defaultDS" />
         
         <property name="hibernate.connection.driver_class" value="${Driver}" />
         <property name="hibernate.connection.url" value="${Url}" />
         <property name="hibernate.connection.username" value="${Login}" />
         <property name="hibernate.connection.password" value="${Password}" />




For making is works, I needed to add this lines into the properties-service.xml file.
this file is in the jboss deploy directory.

Code:
<attribute name="URLList">
      ./conf/myConfig.properties
</attribute>


And that perfectly works!

regards

Bal.


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.