-->
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: Hibernate AND Torque together
PostPosted: Thu Sep 30, 2004 8:37 am 
Newbie

Joined: Thu Sep 30, 2004 6:00 am
Posts: 13
Hello,

I'm using Torque since 2003 for the DB layer.
But it seems the development stopped in september 2003, there are bugs...
I would like to try Hibernate now in order to improve old projects.
Do you know if it is possible to use Hibernate and Torque on a same Tomcat project?
How can I share DB Connection between these two? How may I manage the pool manager?

Thanks


Hibernate version: 2.1.6

Mapping documents: -

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 30, 2004 5:04 pm 
Beginner
Beginner

Joined: Thu Sep 11, 2003 12:53 pm
Posts: 23
I do this on a legacy project. It ain't pretty. My solution was to let to let the container provide the connection via JNDI. Then Torque and Hibernate both use the same connection pool. They are used in separate parts of the application and map to different tables/classes.

I use Tomcat 5, with the built in DBCP connection pool. My Hibernate settings are:

Code:
hibernate.connection.datasource = java:comp/env/jdbc/database_connection
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect


My Tomcat settings are:

Code:
torque.database.default=default
torque.database.default.adapter=mysql
torque.dsfactory.default.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
torque.dsfactory.default.jndi.path=java:comp/env/jdbc/database_connection
torque.idbroker.cleverquantity=true



My web.xml reads: (in part)
Code:
<resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/database_connection</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>


and my context definition (for Tomcat) reads:
Code:
<Context path="/marketing" docBase="marketing" debug="0" reloadable="false">

  <Resource name="jdbc/database_connection"
               auth="Container"
               type="javax.sql.DataSource"/>

  <ResourceParams name="jdbc/database_connection">
    <parameter>
      <name>factory</name>
      <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
    </parameter>

    <parameter>
      <name>maxActive</name>
      <value>20</value>
    </parameter>

    <parameter>
      <name>maxIdle</name>
      <value>5</value>
    </parameter>

    <!-- 0 = wait  -->
    <parameter>
      <name>whenExhaustedAction</name>
      <value>0</value>
    </parameter>

    <parameter>
      <name>maxWait</name>
      <value>10000</value>
    </parameter>

    <parameter>
      <name>removeAbandoned</name>
      <value>true</value>
    </parameter>

    <parameter>
      <name>removeAbandonedTimeout</name>
      <value>600</value>
    </parameter>

    <parameter>
      <name>testOnBorrow</name>
      <value>true</value>
    </parameter>

    <parameter>
      <name>validationQuery</name>
      <value>SELECT 1</value>
    </parameter>

    <!-- MySQL dB username and password for dB connections  -->
    <parameter>
     <name>username</name>
     <value></value>
    </parameter>
    <parameter>
     <name>password</name>
     <value></value>
    </parameter>

    <!-- Class name for mm.mysql JDBC driver -->
    <parameter>
       <name>driverClassName</name>
       <value>com.mysql.jdbc.Driver</value>
    </parameter>

    <!-- The JDBC connection url for connecting to your MySQL dB.
         The autoReconnect=true argument to the url makes sure that the
         mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
         connection.  mysqld by default closes idle connections after 8 hours.
         -->
    <parameter>
      <name>url</name>
      <value>jdbc:mysql://localhost:3306/db</value>
    </parameter>
  </ResourceParams>

</Context>



Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 01, 2004 5:20 am 
Newbie

Joined: Thu Sep 30, 2004 6:00 am
Posts: 13
Thank you very much wglass!


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.