-->
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.  [ 11 posts ] 
Author Message
 Post subject: problem with finding hibernate.cfg.xml automatically
PostPosted: Thu Dec 01, 2005 11:46 am 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
Hibernate version:
3.0.5

Hi, I'm having what ought to be a simple problem with hibernate, but neither I nor a more experienced hibernate user (friend) can figure out what the problem is.

Essentially, I have a hibernate.cfg.xml file in the classpath.
If I point to it in code:

Configuration cfg = new Configuration();
// SHOULD NOT NEED THIS...
File file = new File ("C:\\code\\pinnacle\\src\\hibernate.cfg.xml");
cfg.configure(file);

Then everything runs acceptably.

If I put a hibernate.properties file in the classpath (and remove the hardwired bit above), everything works.

If I just put the hibernate.cfg.xml file in the classpath, things go bad.

10:39:10,763 INFO Environment:464 - Hibernate 3.0.5
10:39:10,773 INFO Environment:477 - hibernate.properties not found
10:39:10,773 INFO Environment:510 - using CGLIB reflection optimizer
10:39:10,773 INFO Environment:540 - using JDK 1.4 java.sql.Timestamp handling
10:39:10,874 INFO Configuration:875 - processing extends queue
10:39:10,874 INFO Configuration:879 - processing collection mappings
10:39:10,874 INFO Configuration:888 - processing association property references
10:39:10,874 INFO Configuration:917 - processing foreign key constraints
10:39:10,884 WARN UserSuppliedConnectionProvider:23 - No connection properties specified - the user must supply JDBC connections
Exception in thread "main" org.hibernate.HibernateException: database product name cannot be null

I think the hibernate.cfg.xml is ok, since 'hardwiring' it works ok. I think the classpath is set up OK, as the hibernate.properties file is picked up ok. As far as I can understand from the docs, the xml file takes precidence over the .properties file, so I should not need the .properties file if I have the XML config.

Any idea why this might be a problem?

-Jim


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 11:55 am 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
Try this, move hibernate.cfg.xml up one level. So it's at:

C:\code\pinnacle\hibernate.cfg.xml

Not sure if this is it. But all my hibernate.cfg.xml files are always one level above the src file.


Top
 Profile  
 
 Post subject: Re: problem with finding hibernate.cfg.xml automatically
PostPosted: Thu Dec 01, 2005 11:57 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
If Hibernate finds your hibernate.cfg.xml but not a hibernate.properties file, you'll get the message "hibernate.properties not found" but everything should still work fine.

Are you certain that when you ran the hard-wired version, the hibernate.properties wasn't also int he Classpath ?

Are you certain the database properties are specified in the hibernate.cfg.xml ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 12:02 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
I think his hibernate.cfg.xml file is constructed fine. When he uses a file object that states where the file is, everything works as expected.

Unless I read his post wrong. :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 12:05 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
mineame wrote:
I think his hibernate.cfg.xml file is constructed fine. When he uses a file object that states where the file is, everything works as expected.

Unless I read his post wrong. :)


The hibernate.cfg.xml has to be in the classpath so it doesn't matter where it starts, just that it ends up on the classpath. By putting it under /src, it will generally get moved into the /classes directory by the IDE if it's building the project automatically.

I maintain a separate /config directory and use ANT to make sure it gets into the correct place...

As for asking about the file contents, that goes with the first question. It's possible the extra properties are coming from the hibernate.properties file if they are both available.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 01, 2005 12:36 pm 
Beginner
Beginner

Joined: Thu Oct 20, 2005 12:34 am
Posts: 28
pksiv wrote:
mineame wrote:
I think his hibernate.cfg.xml file is constructed fine. When he uses a file object that states where the file is, everything works as expected.

Unless I read his post wrong. :)


The hibernate.cfg.xml has to be in the classpath so it doesn't matter where it starts, just that it ends up on the classpath. By putting it under /src, it will generally get moved into the /classes directory by the IDE if it's building the project automatically.

I maintain a separate /config directory and use ANT to make sure it gets into the correct place...

As for asking about the file contents, that goes with the first question. It's possible the extra properties are coming from the hibernate.properties file if they are both available.


I see, I overlooked the possibilites that both files could be getting used.


Top
 Profile  
 
 Post subject: Re: problem with finding hibernate.cfg.xml automatically
PostPosted: Thu Dec 01, 2005 3:04 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
pksiv wrote:
If Hibernate finds your hibernate.cfg.xml but not a hibernate.properties file, you'll get the message "hibernate.properties not found" but everything should still work fine. ?


Hibernate finds the properties file, but not the cfg.xml file. If I remove the properties file to test the xml file, it results in an error unless the xml file is hardwired in.


pksiv wrote:
Are you certain that when you ran the hard-wired version, the hibernate.properties wasn't also int he Classpath ?


Yes.

pksiv wrote:
Are you certain the database properties are specified in the hibernate.cfg.xml


Yes, as when I hard wired the XML file in, everything worked fine.
I'm pretty sure this is not a bug in the file itself, but in hibernate finding it.

Just in case, here's the contents of the two files:
(hibernate.cfg.xml)
<?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 name="Pinnacle">
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.password">password</property>
<property name="connection.url">jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:xxx</property>
<property name="connection.username">pinnacle</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
</session-factory>
</hibernate-configuration>

------
(hibernate.properties)
hibernate.connection.driver_class=oracle.jdbc.driver.OracleDriver
hibernate.connection.password=xxx
hibernate.connection.url=jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:xxx
hibernate.connection.username=pinnacle
hibernate.dialect=org.hibernate.dialect.Oracle9Dialect


Thanks for the help!


Top
 Profile  
 
 Post subject: replying to myself
PostPosted: Thu Dec 01, 2005 3:08 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
Oh, and I tested this by the following:

Test #1: hardwire to XML config. XML config in SRC directory (and is copied to classpath) - RESULT - WORKS

Test #2 no hardwire to XML config. Rely on hibernate to find it. XML in SRC directory (and is copied to classpath) - RESULT - ERROR

Test #3 Remove XML config from SRC and BIN. No hardwire references to XML. Put in hibernate.properties in SRC. - RESULT - WORKS.

So, I only have either the XML OR the properties file at one time (to avoid reading half and half). If I'm testing 'hardwiring', then the properties file is also removed.

-Jim


Top
 Profile  
 
 Post subject: Re: replying to myself
PostPosted: Thu Dec 01, 2005 3:35 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
james_nemesh wrote:
Oh, and I tested this by the following:

Test #1: hardwire to XML config. XML config in SRC directory (and is copied to classpath) - RESULT - WORKS

Test #2 no hardwire to XML config. Rely on hibernate to find it. XML in SRC directory (and is copied to classpath) - RESULT - ERROR

Test #3 Remove XML config from SRC and BIN. No hardwire references to XML. Put in hibernate.properties in SRC. - RESULT - WORKS.

So, I only have either the XML OR the properties file at one time (to avoid reading half and half). If I'm testing 'hardwiring', then the properties file is also removed.

-Jim



Are you sure there isn't more than 1 hibernate.cfg.xml in your classpath ?

Also, try hardwiring the XML to the classpath location, not the src location.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: replying to myself
PostPosted: Thu Dec 01, 2005 6:26 pm 
Newbie

Joined: Thu Dec 01, 2005 11:34 am
Posts: 19
pksiv wrote:

Are you sure there isn't more than 1 hibernate.cfg.xml in your classpath ?

Also, try hardwiring the XML to the classpath location, not the src location.


I'm sure there's only 1 config file. I just started with hibernate, so I've only got a single config generated by the eclipse hibernate tools, and I've been moving it in and out of the source directory by hand.

I've tried 'hard wiring' the file from multiple locations. It works everywhere, because as long as I point a file handle at the file, I'm good to go.

-Jim


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 08, 2006 2:36 pm 
Newbie

Joined: Wed Jan 04, 2006 5:29 am
Posts: 4
Hi there,

Since I had the same problem as you guys, -no DTD's could be found in the classpath- and found the solution to this probl, I'm happy to add a post. (although it seems to be solved)

(Using Hibernate3)
in your mapping files, you must have the exactly SAME doctype as found in the mapping DTD's.

Then and only then you'll see that the dtd's found in hibernate3.jar can be found through the classpath, and running behind a firewall, stand-alone, etc. will be no problem at all.
No local dtd's in your projects to solve this issue, no code to intercept. :-)

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

The same is ofcourse applicable for the configuration file.

HTH, Johan


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