-->
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.  [ 9 posts ] 
Author Message
 Post subject: running hibernate
PostPosted: Wed Jan 12, 2005 6:49 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
[b]Hibernate version:[2.1.7c]
[b]Name and version of the database you are using:[MySQL 1.4]
[b]Name of server: [Tomcat 5.0.28]

hi,

after you run the build file and create the hibernate2.jar file what interface do you use to compile/run your hibernate applications.

do you need to set up any classpaths?

or do you just need to put the following jar files into WEB-INF\lib folder in your webapplication?

cglib-full-2.0.2.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
dom4j-1.4.jar
ehcache-0.9.jar
hibernate2.jar
jta.jar
log4j-1.2.8.jar
mysql-connector-java-3.0.15-ga-bin.jar
odmg-3.0.jar

if any of ye know of any good tutorials on the web could you please please the links.

thanks for your help


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 12, 2005 7:14 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Pretty much yes, put them in the WEB-INF/lib. Also, I recommend implementing the Open-Session-In-View pattern, which will ensure 1) That you have a Hibernate session open for the whole request, and 2) that your configuration is loaded on app startup.

To learn about that one, go to:

http://www.hibernate.org/43.html

Try these tutorials

http://www.onjava.com/pub/a/onjava/2004 ... rnate.html
http://www.onjava.com/pub/a/onjava/2004 ... bapps.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 6:09 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
Thanks cardsharp for your help, ill give those tutorials and the Open-Session-In-View pattern a go.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 11:22 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
in the tutorial it uses HypersonicSQL, i was wondering how you insert the jdbc connection for a MySQL database.

ive inserted this into my server.xml file but this doesnt work. its was in another tutorial i found but not in the ones you posted earlier. im really sure if its the right jdbc connection for MySQL.

Code:
</Context>
         
         
            <Context path="/quickstart" docBase="quickstart">

      <Resource name="jdbc/quickstart" scope="Shareable" type="javax.sql.DataSource"/>

      <ResourceParams name="jdbc/quickstart">

         <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
         </parameter>

   <!-- DBCP database connection settings -->

         <parameter>
            <name>url</name>
            <value>jdbc:postgresql://localhost/quickstart</value>
         </parameter>

         <parameter>
            <name>driverClassName</name><value>org.postgresql.Driver</value>
         </parameter>

         <parameter>
            <name>username</name>
            <value>test</value>
         </parameter>
      
         <parameter>
            <name>password</name>
            <value>test123</value>
         </parameter>


   <!-- DBCP connection pooling options -->

         <parameter>
            <name>maxWait</name>
            <value>3000</value>
         </parameter>

         <parameter>
            <name>maxIdle</name>
            <value>100</value>
         </parameter>
      
         <parameter>
            <name>maxActive</name>
            <value>10</value>
         </parameter>
   
      </ResourceParams>
   </Context>




the tutorial also doesnt specify where you should put the following code
this has to be altered to suit the MySQL
Code:

hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.url=jdbc:hsqldb:/home/davor/hibernate/orders
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect



cheers for the help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 11:30 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
sorry heres my hibernate.cf.xml file as well.

Code:

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
   PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
   <session-factory>
      <property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
      <property name="show_sql">false</property>
      <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>

<!-- Mapping files -->

      <mapping resource="Product.hbm.xml"/>

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



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 13, 2005 5:54 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
You can either configure Hibernate using an XML file or a .property file. The stuff shown with:

hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.url=jdbc:hsqldb:/home/davor/hibernate/orders
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.dialect=net.sf.hibernate.dialect.HSQLDialect

would go into the hibernate.properties file. If you wanted it in the hibernate.cf.xml file, you'd simply do something like:

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:comp/env/jdbc/quickstart</property>
<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<!-- NOTE: this is the dialect for MySQL, did you want that or PostgreSQL? -->

I notice in your configuration you hadn't selected the MySQL Dialect. Hibernate needs some hints as to how to interact with your database. These hints are called a "dialect" and you have to specify the right one in your configuration.

Since you're using Tomcat, the username and password are set up in the Context. Also, I've run into problems with Tomcat's JNDI datasources when I haven't specified the resource-ref in my Web.xml properly. For example, in your /WEB-INF/web.xml you'll want something like:

<resource-ref>
<description>JDBC data source Factory</description>
<res-ref-name>jdbc/quickstart</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>


So, what else? When you say "it doesn't work" what is the exception you're seeing in the log?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 6:02 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
i decided to stick to the example in the tutorial and ive kept the application outside of tomcat for the moment.

its MySQL im trying to get running.

When i try to run a query i get the following error.

Exception: The user must supply a JDBC connection

This is my hibernate.properties file.

Code:

hibernate.connection.username=test123
hibernate.connection.password=test123
hibernate.connection.url=jdbc:mysql://localhost:3306/tutorial?autoReconnect=true
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect
hibernate.connection.pool_size = 20
hibernate.statement_cache.size = 6
hibernate.show_sql = true



the hibernate.connection.url seems to be correct as i extracted the files into the relative folders just to be on the safe side although its giving me the error above about a jdbc connection but i think the problem may be here.

Code:

hibernate.connection.url=jdbc:mysql://localhost:3306/tutorial?



the name of my database is "tutorial". is the right syntax for a MySQL database?

thanks again for the help


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 9:07 am 
Newbie

Joined: Tue Jan 11, 2005 12:52 pm
Posts: 17
sorry a slight type in this line

Quote:
the

hibernate.connection.url

seems to be correct as i extracted the files into the relative folders just to be on the safe side although its giving me the error above about a jdbc connection but i think the problem may be here.


it should have read
"the

hibernate.connection.driver_class=com.mysql.jdbc.Driver

seems to be correct as i extracted the files into the relative folders just to be on the safe side although its giving me the error above about a jdbc connection but i think the problem may be here."


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 14, 2005 1:12 pm 
Regular
Regular

Joined: Tue Jun 22, 2004 8:01 pm
Posts: 106
Location: PowderTown, Utah, USA
Do you also have the hibernate.cfg.xml file in your classpath? It could be that hibernate is picking that up instead of your hibernate.properties file. If you're going to use hibernate.properties instead of hibernate.cfg.xml, it's a good idea to remove the hibernate.cfg.xml from the classpath.


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