-->
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.  [ 6 posts ] 
Author Message
 Post subject: org.hibernate.HibernateException: could not find file
PostPosted: Tue Nov 29, 2005 1:12 pm 
Newbie

Joined: Tue Nov 29, 2005 7:08 am
Posts: 2
hi every body! I have a little problem with a simple example of 'Hello World'.
My architecture is:
-windows xp pro
-IDE: Netbeans 4.1
I don't understand the message error... the file exists... May i must configure Netbeans?...

A view of my project path:
+Hello1
+build.xml
+src
+hibernate.cfg.xml
+hello1
Main.java
Message.java
Message.hbm.xml
+lib
all the lib i need...

Hibernate version:
the last. (3.1 i believe).

Mapping documents:

build.xml:
<?xml version="1.0" encoding="UTF-8"?>


<project name="Hello1" default="default" basedir=".">

<description>Builds, tests, and runs the project Hello1.</description>

<import file="nbproject/build-impl.xml"/>


</project>


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-mapping-3.0.dtd">

<hibernate-configuration>

<session-factory>

<mapping resource="hello1/Message.hbm.xml"/>

</session-factory>

</hibernate-configuration>

Message.hbm.xml:
<?xml version="1.0" encoding="UTF-8"?>

<!--
Document : Message.hbm.xml
Created on : 24 novembre 2005, 10:13
Author : gwennaël
Description:
Purpose of the document follows.
-->
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="hello1.Message"
table="message.messages3">
<id
name="id"
column="id">
<generator class="increment"/>
</id>
<property
name="text"
column="text"/>
</class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
SessionFactory sessions = configuration.buildSessionFactory();
Session session=sessions.openSession();
Transaction tx=session.beginTransaction();
hello1.Message message = new hello1.Message("Hello World");
session.save(message);
tx.commit();
session.close();


Full stack trace of any exception that occurs:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN Please initialize the log4j system properly.

org.hibernate.HibernateException: could not find file: D:\developpement\ihm\Hello1\src\hibernate.cgf.xml

at org.hibernate.cfg.Configuration.configure(Configuration.java:1303)

at hello1.Main_1.main(Main_1.java:56)

Caused by: java.io.FileNotFoundException: D:\developpement\ihm\Hello1\src\hibernate.cgf.xml (Le fichier spécifié est introuvable)

at java.io.FileInputStream.open(Native Method)

at java.io.FileInputStream.<init>(FileInputStream.java:106)

at org.hibernate.cfg.Configuration.configure(Configuration.java:1300)

... 1 more

Exception in thread "main"

Java Result: 1


Name and version of the database you are using:
the last version of MySQL and i have created the database messages

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



My java code:

Main.java:

package hello1;

import com.sun.corba.se.internal.iiop.messages.Message;
import javax.sql.DataSource;
import org.hibernate.*;
import org.hibernate.cfg.*;
import junit.framework.TestCase;
import java.io.*;
import org.hibernate.Session;
//import org.hibernate.dialect.HSQLDialect;
import org.hibernate.dialect.MySQLDialect;
/**
*
* @author gwennaël
*/
public class Main{

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
File cfgFile = new File(new File("").getAbsolutePath()+
File.separator+"src"+File.separator+"hibernate.cgf.xml");
Configuration configuration = new Configuration();

configuration.setProperties(System.getProperties());
configuration.setProperty(
Environment.DRIVER,
"com.mysql.jdbc.Driver");
configuration.setProperty(
Environment.URL,
"jdbc:mysql://localhost:3306/");
configuration.setProperty(
Environment.USER, "root");
configuration.setProperty(
Environment.PASS, "gwennael1");
configuration.setProperty(
Environment.DIALECT,
org.hibernate.dialect.MySQLDialect.class.getName());
configuration.setProperty(
Environment.SHOW_SQL, "true");
configuration.configure(cfgFile);
configuration.addResource(new File("").getAbsolutePath()+
File.separator+"hello1"+File.separator+"Message.hbm.xml");

SessionFactory sessions = configuration.buildSessionFactory();
Session session=sessions.openSession();
Transaction tx=session.beginTransaction();
hello1.Message message = new hello1.Message("Hello World");
session.save(message);
tx.commit();
session.close();
}
}



Message.java:

/*
* Message.java
*
* Created on 24 novembre 2005, 09:19
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/

package hello1;

/**
*
* @author gwennaël
*/
public class Message {
private long id;
private String text;

/** Creates a new instance of Message */
public Message() {
}
public Message(String text){
this.id=id;
this.text=text;
}
private void setId(long id){
this.id=id;
}
private void setText(String text){
this.text=text;
}
public long getId(){
return this.id;
}

public String getText(){
return this.text;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:15 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Follow this step by step:

http://www.hibernate.org/152.html

You can start at Day 2 if you have Hibernate 3.1.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 1:18 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
looks like it could be a spelling error in the file name...

Caused by: java.io.FileNotFoundException: D:\developpement\ihm\Hello1\src\hibernate.cgf.xml (Le fichier spécifié est introuvable)

should be \hibernate.cfg.xml


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not the only thing wrong with the code shown. There are many minor mistakes in it. Better start fresh with a step-by-step-copy-the-files-there tutorial.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 29, 2005 4:38 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
yeah, i wasn't trying to suggest otherwise. just to give them a heads up about the error they're getting.


Top
 Profile  
 
 Post subject: oki
PostPosted: Wed Nov 30, 2005 9:31 am 
Newbie

Joined: Tue Nov 29, 2005 7:08 am
Posts: 2
Thanks for your replies. I am going to follow a simple example (in the doc tutorial) step by step... But i believe i have already done this work... The code i give is based on this, and it is not very an advanced code...
Maybe have i make a mistake?

I will come back soon


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