-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to load hibernate.cfg.xml in annotation mode...
PostPosted: Fri Nov 17, 2006 8:00 pm 
Newbie

Joined: Fri Nov 17, 2006 7:24 pm
Posts: 16
Thank you for reading my post
Hibernate version: 3.2

I have problem with loading hibernate.cfg.xml in my application.
here is the code snippet:
Code:

package learn_hiber.chapter4;

import java.io.File;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;

public class GenerateSchema
{

    public static void main(String[] args)
    {
       // Amended to allow a path (to the hibernate.cfg.xml) to
       // be passed to the configuration.
        AnnotationConfiguration cfg = ExampleConfiguration.getConfig();;
       
        cfg.addFile(new File("learn_hiber/hibernate.cfg.xml"));
       
        SchemaExport schemaExport = new SchemaExport(cfg);
        schemaExport.create(true, true);
    }
}


when i try to run this code it return
Code:
Exception in thread "main" org.hibernate.MappingException: Could not read mapping document from file: learn_hiber\hibernate.cfg.xml
        at org.hibernate.cfg.Configuration.addFile(Configuration.java:297)
        at learn_hiber.chapter4.GenerateSchema.main(GenerateSchema.java:17)
Caused by: java.io.FileNotFoundException: learn_hiber\hibernate.cfg.xml (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at org.hibernate.cfg.Configuration.addFile(Configuration.java:294)
        ... 1 more
Java Result: 1



while my directory structure is like:
src folder contains:
-learn_hiber\chapter4
-learn_hiber\hibernate.cfg.xml
-learn_hiber\log4j.properties

the chapter 4 folder contains my annotated classes source code
src is roof folder for all my source codes.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 19, 2006 3:14 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Maybe you should try with slash (/) instead of antislash ? I suspect the system is understanding \ as a "despecializer" in your case.

\ is not to be used in Java, it's a bizarre windows choice, because it can sometimes conflict with the usual \ used in programming (\n, \r, \t, etc.). When asking for paths, Java will convert your slashes for the right platform (see System.getProperties() => one is indicating what it used : / or \, but code should always use /).

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 1:52 pm 
Newbie

Joined: Fri Nov 17, 2006 7:24 pm
Posts: 16
Thanks, but it does not helps.
it looks like that it does not find the mapping file even after changing.
Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 20, 2006 3:44 pm 
Beginner
Beginner

Joined: Tue Nov 29, 2005 4:42 pm
Posts: 49
Location: Atlanta, GA
Have you tried using a full path? Sometimes a FileNotFoundException is just that. It can't find your file. Using a full path might help figure out if your relative path is correct.

Charlie


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