I am new to Hibernate, reading this book "Java persistence with Hibernate" and I am trying to implement the example from there. So far my Ant build is successful, but when I try to execute the class containing the main method I am getting this error message:
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.3
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
19-Nov-2011 18:40:09 org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
19-Nov-2011 18:40:09 org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
19-Nov-2011 18:40:09 org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at persistence.HibernateUtil.<clinit>(Unknown Source)
at hello.Driver.main(Unknown Source)
Caused by: org.hibernate.HibernateException: /hibernate.cfg.xml not found
at org.hibernate.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:147)
at org.hibernate.cfg.Configuration.getConfigurationInputStream(Configuration.java:1405)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1427)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
... 2 more
It is clear that hibernate can't find my config file, which is located in the root dir.
Project
+lib
<all required libraries>
+src
+hello
HelloWorld.java
Message.java
message.hbm.xml
+persistence
HibernateUtil.java
build.xml
hibernate.cfg.xml
My the complete source code can be found here: http://pastebin.com/bGDUrxUf
I have a running MySQL server with a database hibernateapp and table messages
Thanks :)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…