-->
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.  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: hibernate.properties file
PostPosted: Mon Aug 08, 2005 2:07 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Hi,

I am working on a tutorial of Hibernate and have a few questions. First of all, what is Hibernate's classpath relative to my application? I have:
Code:
drwxr-xr-x  2 root root 4096 Aug  8 11:00 bin
drwxr-xr-x  2 alex alex 4096 Aug  8 10:59 lib
drwxr-xr-x  2 alex alex 4096 Aug  8 10:59 src
-rw-r--r--  1 alex alex 1093 Aug  3 03:17 build.xml

and src is:
Code:
-rw-r--r--  1 root root  394 Aug  8 10:59 hibernate.properties
-rw-r--r--  1 alex alex 1316 Aug  8 10:43 HibernateUtil.java
-rw-r--r--  1 root root 1191 Aug  6 11:22 HibernateUtil.java.original
-rw-r--r--  1 alex alex  654 Aug  5 05:50 SKUManager.java
-rw-r--r--  1 alex alex  417 Aug  5 05:10 SKU.hbm.xml
-rw-rw-r--  1 alex alex  959 Aug  5 05:01 hibernate.cfg.xml.original
-rw-r--r--  1 alex alex  475 Aug  3 02:11 SKU.java

Now, as I understand I can define datasource properties in either hibernate.properties or hibernate.cfg.xml, right? I am using hibernate.properties:
Code:
bernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/mydb
hibernate.connection.username = root
hibernate.connection.password =
hibernate.dialect = net.sf.hibernate.dialect.MySQLDialect
hibernate.c3p0.min_size=5
hibernate.c3p0.max_size=20
hibernate.c3p0.timeout=300
hibernate.c3p0.max_statements=50
hibernate.c3p0.idle_test_period=3000


But where the file should go? What is the classpath? I think this is related to the error I am getting when building:

Code:
run:
     [java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
     [java] log4j:WARN Please initialize the log4j system properly.
     [java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java]     at HibernateUtil.<clinit>(Unknown Source)
     [java]     at SKUManager.createAndStoreEvent(Unknown Source)
     [java]     at SKUManager.main(Unknown Source)
     [java] Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
     [java]     at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
     [java]     at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
     [java]     at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:374)
     [java]     at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
     [java]     at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
     [java]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
     [java]     ... 3 more
     [java] Java Result: 1


thanks for your help because this drives me nuts!


Top
 Profile  
 
 Post subject: classpath
PostPosted: Mon Aug 08, 2005 2:15 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Try running Ant with -debug or -verbose parameters like
and -debug your-target-name
then Ant will print what is the classpath is, then you can:
- adjust the class path to point to include desired directories and jar files;
- make sure that necessary files get copied into classpath;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 2:21 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
thanks a lot, at least now I can see what's going on.
So, I see that all of my jar files in lib directory are in the classpath, but what about hibernate.properties, it does not show up in the classpath.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 2:27 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Also, you said:
Quote:
make sure that necessary files get copied into classpath

How exectly do I do this?


Top
 Profile  
 
 Post subject: copy
PostPosted: Mon Aug 08, 2005 2:33 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
webtekie wrote:
Also, you said:
Quote:
make sure that necessary files get copied into classpath

How exectly do I do this?

Most likely in you Ant's build.xml file.
Check also which H version you use: in H3.1 dialect would be org.hibernate.dialect.MySQLDialect (different package name)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 2:57 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Ok, so I've included hibernate.properties into the build and it is not sets in the classpath along with jar files from my lib directory. Also, I've changed hbernate.dialect, and still I get error Hibernate Dialect must be explicitly set. What am I still doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 3:17 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Sorry, meant to say "it is now set" in classpath...


Top
 Profile  
 
 Post subject: cp
PostPosted: Mon Aug 08, 2005 3:52 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
webtekie wrote:
thanks a lot, at least now I can see what's going on.
So, I see that all of my jar files in lib directory are in the classpath, but what about hibernate.properties, it does not show up in the classpath.

There should be some directories in the classpath and hibernate.properties should be there ( note: directories and jar files content does not appear in the print)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 4:04 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Yes I can see them in the classpath. I replaced hibernate.properties with hibernate.cfg.xml which I understand are same thing...
Code:
Execute:Java13CommandLauncher: Executing '/usr/local/java/j2sdk1.4.2_08/jre/bin/java' with arguments:
'-classpath'
'/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/bin:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/README.html:/home/jboss-4.0.2/server/default/deploy/
hibernate_test.war/lib/antlr-2.7.5H3.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/asm-attrs.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/li
b/asm.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/cglib-2.1.2.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/commons-collections-2.1.1.j
ar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/commons-logging-1.0.4.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/dom4j-1.6.jar:/home/jbos
s-4.0.2/server/default/deploy/hibernate_test.war/lib/ehcache-1.1.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/hibernate.cfg.xml:/home/jboss-4.0.2/server/defa
ult/deploy/hibernate_test.war/lib/hibernate3.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/jta.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/
lib/log4j-1.2.9.jar:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/log4j.properties:/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/mysql-connector-
java-3.1.9-bin.jar'
'SKUManager'
'${action}'

The ' characters around the executable and arguments are
not part of the command.
     [java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
     [java] log4j:WARN Please initialize the log4j system properly.
     [java] Initial SessionFactory creation failed.org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java]     at HibernateUtil.<clinit>(Unknown Source)
     [java]     at SKUManager.main(Unknown Source)
     [java] Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
     [java]     at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
     [java]     at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
     [java]     at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:374)
     [java]     at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:110)
     [java]     at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1502)
     [java]     at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1031)
     [java]     ... 2 more
     [java] Java Result: 1


thanks for you help, really appreciate it.


Top
 Profile  
 
 Post subject: cp
PostPosted: Mon Aug 08, 2005 4:20 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
From what I see:
- the classpath does not include
/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/WEB-INF/classes directory (where all the config files should be )
- also
/home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib entry seems strange because standard location for jar files within war file is WEB-inf/lib
- it includes /home/jboss-4.0.2/server/default/deploy/hibernate_test.war/lib/log4j.properties
which does not make any sense

I suggest you to get familiar with classpath concept in java: http://mindprod.com/jgloss/classpath.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 4:29 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Wait, I am not running this application as a web application now, so I don't have WEB-INF directory. I execute application from ant: ant run...so it takes classes from bin directory:

Quote:
<project name="hibernate-tutorial" default="compile">

<property name="sourcedir" value="${basedir}/src"/>
<property name="targetdir" value="${basedir}/bin"/>
<property name="librarydir" value="${basedir}/lib"/>

<path id="libraries">
<fileset dir="${librarydir}">
<include name="*.*"/>
</fileset>
</path>

<target name="clean">
<delete dir="${targetdir}"/>
<mkdir dir="${targetdir}"/>
</target>

<target name="compile" depends="clean, copy-resources">
<javac srcdir="${sourcedir}"
destdir="${targetdir}"
classpathref="libraries"/>
</target>

<target name="copy-resources">
<copy todir="${targetdir}">
<fileset dir="${sourcedir}">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>

<target name="run" depends="compile">
<java fork="true" classname="SKUManager" classpathref="libraries">
<classpath path="${targetdir}"/>
<arg value="${action}"/>
</java>
</target>
</project>

log4j.properties I put in lib thinking that it will be appended to classpath so I won't get log4j errors.
As far as I can see the problem is with hibernate.cfg.xml file's dialect property.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 4:37 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Post your current hibernate.cfg.xml.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 4:45 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mydb</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password"></property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<property name="hibernate.cache.provider_class">
org.hibernate.cache.HashtableCacheProvider
</property>
<property name="hibernate.hbm2ddl.auto">update</property>

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

</session-factory>

</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 4:58 pm 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Leave out the hibernate. inside your 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:3306/mydb</property>
        <property name="connection.username">root</property>
        <property name="connection.password"></property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="show_sql">true</property>
        <property name="transaction.factory_class">
             org.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="cache.provider_class">
             org.hibernate.cache.HashtableCacheProvider
        </property>
        <property name="hbm2ddl.auto">update</property>

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

    </session-factory>

</hibernate-configuration>


Best regards
Sven


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 08, 2005 5:02 pm 
Beginner
Beginner

Joined: Wed Aug 03, 2005 3:50 pm
Posts: 23
Sorry, I don't understand. Leave hibernate out of where inside hibernate.cfg.xml?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 17 posts ]  Go to page 1, 2  Next

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.