-->
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.  [ 30 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: hibernate.properties not found
PostPosted: Fri Nov 07, 2003 12:52 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
simple question:

i have a simple application consisting of:

- A Value Object(.java file)
- The XML mapping (.hbm.xml file)
- A hibernate.properties file
- A java class that makes a jdbc connection and does a simple test

All the files are in the same directory, but still when i run the test it says:
"hibernate.properties not found"

Where is hibernate.properties supposed to be?

thanks/cheers


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
In the root of the classpath

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 2:02 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
ok,


but... sorry if the question is silly, anyway its in Hibernate Beginners :-)

i have all that files in a common directory:

/home/myuser/testapp

java is installed in /opt/sun-jdk-1.4.01/

where exactly is that "root of the classpath" ???

thanks again...

cheers


Top
 Profile  
 
 Post subject: locations of hibernate.properties
PostPosted: Fri Nov 07, 2003 2:06 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
If you are writing a stand-alone application (not a webapp), the main directory of your project is where you want to put the hibernate.properties file. If you are using a webapp, you want to put it in your project's WEB-INF/classes folder.

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 2:14 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
ok, my app is a stand-alone application...
and the hibernate.properties file is in the same directory as all of the other files...

still, when i run the program it says it cannot find hibernate.properties.

any idea of what the problem might be?

thanks


Top
 Profile  
 
 Post subject: What is your code snippet for building the app?
PostPosted: Fri Nov 07, 2003 2:33 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
Are you invoking the java application from the same directory as your hibernate.properties file? Is your configuration build like this:

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.cfg.Configuration;

public class Me {

public static void main(String[] args) {
Configuration cfg = null;
SessionFactory sf = null;
try {
cfg = (new Configuration()).addFile("Misc.hbm.xml");
sf = cfg.buildSessionFactory();
System.out.println("Three.");
Session sess = sf.openSession();
sess.close();

} catch (HibernateException he) {
System.out.println("Hibernate exception: " + he.getMessage());
} catch (IOException ioe) {
}
}
}

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 2:42 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
yes, i am invoking them from the same directory.

i put all the files in:
http://azambuja.homelinux.com/files

take a look...

thank you very much for your help!

Marcelo


Top
 Profile  
 
 Post subject: which way do you want it? Supplied JDBC or auto JDBC?
PostPosted: Fri Nov 07, 2003 3:30 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
You probably shouldn't .addProperties an empty Properties object, but it worked with our without that call. I did have to rename your file, supplied as hibernate.txt, to the proper name of hibernate.properties so it would be seen and used (with the database name, username, and password changed for my MySQL database).

The problem seems to be somewher else. I recommend you check your classpath and post the output messages (errors, diagnostics, etc.).

I see your demo code manually creates the JDBC connection. The code I included works on it's own by using information in the hibernate.properties file to do that for you. If you ever need the raw JDBC connection, just call session.connection() to use it as a normal JDBC connectin, without hibernate's influence.

Again, my one change is marked in the below comments but it worked both with and without that alteration.

cfg = new Configuration() .addClass(Person.class);
// removed useless addProperties - yours is empty!
// .addProperties(props);

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 3:41 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
ok, here's the output:

Code:
azambuja@proc-78288 ex $ java PersonDemo
Nov 7, 2003 5:38:18 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.3
Nov 7, 2003 5:38:18 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: [b]hibernate.properties not found[/b]
Nov 7, 2003 5:38:18 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Nov 7, 2003 5:38:19 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
Nov 7, 2003 5:38:19 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: Person.hbm.xml
Nov 7, 2003 5:38:23 PM net.sf.hibernate.util.XMLHelper$ErrorLogger error
SEVERE: Error parsing XML: XML InputStream(12)
org.xml.sax.SAXParseException: The content of element type "id" is incomplete, it must match "(meta*,column*,generator)".
        at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.handleEndElement(Unknown Source)
        at org.apache.xerces.impl.dtd.XMLDTDValidator.endElement(Unknown Source)        at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.dom4j.io.SAXReader.read(SAXReader.java:339)
        at net.sf.hibernate.cfg.Configuration.addInputStream(Configuration.java:252)
        at net.sf.hibernate.cfg.Configuration.addClass(Configuration.java:286)
        at PersonDemo.run(PersonDemo.java:43)
        at PersonDemo.main(PersonDemo.java:23)
Nov 7, 2003 5:38:23 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Person -> Person
Nov 7, 2003 5:38:24 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Nov 7, 2003 5:38:24 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Nov 7, 2003 5:38:25 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 7, 2003 5:38:25 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
WARNING: No dialect set - using GenericDialect: The dialect was not set. Set the property hibernate.dialect.
Nov 7, 2003 5:38:25 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.GenericDialect
Nov 7, 2003 5:38:25 PM net.sf.hibernate.connection.UserSuppliedConnectionProvider configure
WARNING: No connection properties specified - the user must supply JDBC connections
Nov 7, 2003 5:38:25 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use outer join fetching: false
Nov 7, 2003 5:38:25 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use scrollable result sets: false
Nov 7, 2003 5:38:28 PM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JDNI name configured
Nov 7, 2003 5:38:28 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Query language substitutions: {}
Person = Jo?o da Silva5377496185


hope it can help!

thanks one more time ;-)

Marcelo


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 3:42 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
the are there just because i wanted to highlight them, but as you and i can see it did not make the text bold!

Marcelo


Top
 Profile  
 
 Post subject: aha! <generator> tag missing on <id.... > ....
PostPosted: Fri Nov 07, 2003 4:30 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
I see the problem. Primary keys <id.../> need to have a 'generator' tag inside them. I didn't see that error message since I was using Eclipse v2.1. Once I used the command line java, I saw that error.

The fix is to change your <id ../>.. </id> tag from:

<id name="id" type="string" unsaved-value="null" >
<column name="ID" sql-type="varchar(10)" not-null="true"/>
</id>

TO include a GENERATOR tag:

<id name="id" type="string" unsaved-value="null" >
<column name="ID" sql-type="varchar(10)" not-null="true"/>
<generator class="assigned" />
</id>

I normally used "native" as the Generated type under MySQL and with the type being an int(11), or bigint (Long to hibernate) using AUTO_INCREMENT. I honestly don't know how Strings work with mysql for auto-key generation.

Anyway, with the generator set appropriately, the errors disappear:

D:\Code\HIBERN~1>java -cp mysql-connector-java-3.0.9-stable-bin.jar;commons-lang-2.0.jar;hibernate2.jar;.;dom4j.jar;comm
ons-logging-1.0.3.jar;commons-beanutils-1.6.1.jar;commons-collections-2.1.jar;cglib.jar PersonDemo
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.0.3
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hi
bernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.MySQLDialect, hibernate.jdbc.use
_streams_for_binary=true, hibernate.jdbc.batch_size=0, hibernate.query.substitutions=true 1, false 0, yes 'Y', no 'N', h
ibernate.query.imports=net.sf.hibernate.test, net.sf.hibernate.eg, hibernate.proxool.pool_alias=pool1, hibernate.connect
ion.username=X, hibernate.connection.url=jdbc:mysql://localhost:3306/test, hibernate.show_sql=false, hibernate.c
onnection.password=Y, hibernate.statement_cache.size=25, hibernate.connection.pool_size=1}
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using java.io streams to persist binary types
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Environment <clinit>
INFO: JVM proxy support: true
Nov 7, 2003 3:19:41 PM net.sf.hibernate.cfg.Configuration addClass
INFO: Mapping resource: Person.hbm.xml
Nov 7, 2003 3:19:42 PM net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: Person -> Person
Nov 7, 2003 3:19:42 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
Nov 7, 2003 3:19:42 PM net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
Nov 7, 2003 3:19:42 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Nov 7, 2003 3:19:42 PM net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.MySQLDialect
Nov 7, 2003 3:19:42 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 1
Nov 7, 2003 3:19:42 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/test
Nov 7, 2003 3:19:42 PM net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=X, password=Y}
Nov 7, 2003 3:19:42 PM net.sf.hibernate.ps.PreparedStatementCache <init>
INFO: prepared statement cache size: 25
Nov 7, 2003 3:19:42 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use outer join fetching: true
Nov 7, 2003 3:19:42 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Use scrollable result sets: true
Nov 7, 2003 3:19:42 PM net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JDNI name configured
Nov 7, 2003 3:19:42 PM net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: Query language substitutions: {no='N', true=1, yes='Y', false=0}
Person = Joπo da Silva6786955904

FYI, the generators can be found at:
http://www.hibernate.org/hib_docs/refer ... pping.html

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 12:17 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
hello,

unfortunately i keep getting the hibernate.properties not found message...

this is kinda supernatural :-)

thanks for your time.

Marcelo


Top
 Profile  
 
 Post subject: Funny, mine say similar but works
PostPosted: Mon Nov 10, 2003 12:50 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
No seeing the hibernate.properties file means it is not in a place where the classpath can find it. So, let's backup and try a different question.

Are you running this as a standalone app or a webapp?

If a standalone app, is the hibernate.properties file located in the directory /home/myuser/testapp and does your classpath reference that directory (OR you run java from that directory and have added the current directory notation '.' to the classpath) ?

If it is a webapp, what is the exact path to your properties file? Perhaps
home/myuser/testapp/WEB-INF/classes/hibernate.properties?

Regards,
David


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2003 3:12 pm 
Newbie

Joined: Fri Nov 07, 2003 12:36 pm
Posts: 16
Location: Porto Alegre, RS - Brasil
standalone app
the hibernate.properties is in the same dir as the other files
the classpath is:
Code:
azambuja@proc-78288 hibernate $ echo $CLASSPATH
/opt/sun-jdk-1.4.2.01/jre/lib:/opt/sun-jdk-1.4.2.01/lib/tools.jar:/opt/sun-jdk-1.4.2.01/jre/lib/rt.jar:/usr/share/ant/lib/ant.jar:/usr/share/ant/lib/optional.jar:/usr/share/postgresql/lib/postgresql.jar:.



thanks again.

Marcelo


Top
 Profile  
 
 Post subject: missing something
PostPosted: Mon Nov 10, 2003 3:52 pm 
Regular
Regular

Joined: Sun Sep 21, 2003 11:43 pm
Posts: 85
Location: Massachusetts
There has to be something wrong with your file locations or your classpath. Using hibernate 2.0.3, I created a simple webapp where all jar's are in the main directory, the hibernate.properties file is in the main directory, my simple 'Dgf.java' class is in the main directory, and my supporting class are there. It created a sessionFactory fine and found the hibernate.properties file in that directory.

Please output the following, removing private information as necessary:
1) pwd (or echo it)
2) echo $CLASSPATH
3) ls
4) explain how you're invoking your application (ant, java, etc.). It looks like you're using "java PersonDemo" but you're not specifying the .jar files. I have to set my CLASSPATH to include the relative or full paths to the following jars:

CLASSPATH=.;./hibernate2.jar;./commons-lang-2.0.jar;./dom4j.jar;./commons-logging-1.0.3.jar;./commons-beanuti
ls-1.6.1.jar;./commons-collections.jar;./mysql-connector-java-3.0.9-stable-bin.jar;./cglib.jar;./cglib-asm.jar

Regards,
David


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