-->
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: Problem wih connection properties in hibernate.cfg.xml
PostPosted: Wed Aug 27, 2003 12:56 pm 
Newbie

Joined: Wed Aug 27, 2003 12:26 pm
Posts: 5
Hi all,

I am having a problem with setting up the connection to the database. My connection properties are specified in hibernate.cfg.xml and I have tested that the database is working and acessible through the specified url/username/password. However, it says that no connection properties have been specified.

Furthermore, it says it cannot find hibernate.properties, which is in the current directory (which is the root classpath directory since my classpath contains "." and i am not using packages)

anyway, here is my small test program which produces the error, my hibernate.cfg.xml, and the errors i am getting. Any help will be greatly appreciated =) Thanks

Test.java:
=======

import net.sf.hibernate.*;
import net.sf.hibernate.cfg.*;

import net.sf.hibernate.tool.hbm2ddl.SchemaExport;

import java.io.File;

public class Test
{
public static void main(String[] args)
{
try
{
Configuration cfg = new Configuration().configure(new File("hibernate.cfg.xml"));
new SchemaExport(cfg).create(true, true);
}
catch(Exception e)
{
System.out.println(e);
}
}
}
===============================================


hibernate.cfg.xml:
===========

<?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.driver_class">com.mysql.jdbc.Driver</property>
<property name="conection.url">jdbc:mysql:///aleh</property>
<property name="conection.username">boffin</property>
<property name="connection.password"/>
<property name="connection.pool_size">1</property>
<property name="connection.statement_cache.size">25</property>

<property name="show_sql">false</property>
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>

<!-- Mapping files -->
<mapping resource="User.hbm.xml"/>
<mapping resource="Language.hbm.xml"/>
<mapping resource="LanguageAbility.hbm.xml"/>

</session-factory>

</hibernate-configuration>

===============================================


Stderr output:
=========

28/08/2003 02:16:57 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.2
28/08/2003 02:16:57 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
28/08/2003 02:16:57 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
28/08/2003 02:16:57 net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
28/08/2003 02:16:57 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: User.hbm.xml
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: User -> user
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindCollection
INFO: Mapping collection: User.languageAbilities -> user_languageabilities
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Language.hbm.xml
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Language -> languages
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindSubclass
INFO: Mapping subclass: WrittenLanguage -> languages
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindSubclass
INFO: Mapping subclass: SpokenLanguage -> languages
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: LanguageAbility.hbm.xml
28/08/2003 02:16:58 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: LanguageAbility -> languageability
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration configure
INFO: Configured SessionFactory: null
28/08/2003 02:16:58 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
28/08/2003 02:16:58 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
28/08/2003 02:16:58 net.sf.hibernate.connection.UserSuppliedConnectionProvider configure
WARNING: No connection properties specified - the user must supply JDBC connections
java.lang.UnsupportedOperationException: The user must supply a JDBC connection
at net.sf.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:32)
at net.sf.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:110)
at net.sf.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:78)
at Test.main(Test.java:15)

===============================================


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 1:03 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Configuration cfg = new Configuration().configure(new File("hibernate.cfg.xml"));


Change this to:

Code:
Configuration cfg = new Configuration().configure();


This will automatically load "hibernate.cfg.xml" from the root of your classpath. You only have to specify a new name (but not with File()) if it is placed in a package/directory.

Don't use a properties file _and_ a cfg.xml, decide whats best for your scenario. Read the Quickstart:

[url]http://www.hibernate.org/hib_docs/examples/quickstart/html/quickstart.html
[/url]

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 7:35 pm 
Newbie

Joined: Wed Aug 27, 2003 12:26 pm
Posts: 5
ok, thanks for the tips!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 7:50 pm 
Newbie

Joined: Wed Aug 27, 2003 12:26 pm
Posts: 5
hmmm... i followed your advice and changed
Code:
Configuration cfg = new Configuration().configure(new File("hibernate.cfg.xml"));

to
Code:
Configuration cfg = new Configuration().configure();

and now hibernate can not find hibernate.cfg.xml at all. (This was the reason I had that line in the first place)

From the documentation, it seems to say that the hibernate.cfg.xml should be in the root of the classpath. My classpath is set to "c:\test;." I am comiling and running my program from within the directory "c:\test". My java code and hibernate.cfg.xml is inside this directory and the code compiles fine.

Perhaps i am confused about the meaning of "the root of the classpath" Is my classpath set wrongly? All the third party libraries required by hibernate I have put in %JAVAHOME%\jre\lib\ext because it became too tedious to enter each library into my classpath... could this be related to the problem?

Anyway here is my new error output. Thanks in advance for any assistance..

28/08/2003 09:11:13 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.2
28/08/2003 09:11:13 net.sf.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
28/08/2003 09:11:13 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
28/08/2003 09:11:13 net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
28/08/2003 09:11:13 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
28/08/2003 09:11:13 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
WARNING: /hibernate.cfg.xml not found


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Quote:
Perhaps i am confused about the meaning of "the root of the classpath" Is my classpath set wrongly? All the third party libraries required by hibernate I have put in %JAVAHOME%\jre\lib\ext because it became too tedious to enter each library into my classpath... could this be related to the problem?


Yes. Fix your setup.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.