-->
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.  [ 7 posts ] 
Author Message
 Post subject: hibernate.cfg.xml not found.
PostPosted: Mon Feb 22, 2010 4:29 pm 
Newbie

Joined: Mon Feb 22, 2010 4:14 pm
Posts: 4
Hi everybody,
I've just started to learn hibernate, so I follow this tutorial. I execute this command:
Code:
mvn exec:java -Dexec.mainClass="org.hibernate.tutorial.EventManager" -Dexec.args="store"
and I got this error:
Code:
INFO] [exec:java {execution: default-cli}]
18 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
20 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - hibernate.properties not found
24 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
29 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
130 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
130 [org.hibernate.tutorial.EventManager.main()] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
Initial SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. null

/hibernate.cfg.xml not found
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch

build shows that hibernate.cfg.xml file is not found, but in my workspace I have at this path : /classes/org/hibernate/tutorial/domain.
I suppose that I've to add this file to the CLASSPATH, but I don't know how I can do it with mavec-exec plugin.
Thank you in advance for your help.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Tue Feb 23, 2010 4:53 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
Quote:
Save this file as hibernate.cfg.xml into the src/main/resources directory.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Wed Feb 24, 2010 6:19 am 
Newbie

Joined: Mon Feb 22, 2010 4:14 pm
Posts: 4
Thank you for your reply.
I prefer to indicate to maven to look for hibernate.cfg.xml file in src/main/resources/org/hibernate/tutorial, instead of looking for it directly in src/main/resources.
Is there any way to do this? for example using a particular maven plugin for copying file. Or, by default hibernate.cfg.xml must be in this path src/main/resources?


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Wed Feb 24, 2010 6:29 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
You can put the hibernate.cfg.xml anywhere you want, that's not maven's part. But if you do so, you have to change the class where your SessionFactory is being built.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Wed Feb 24, 2010 7:11 am 
Newbie

Joined: Mon Feb 22, 2010 4:14 pm
Posts: 4
Thank you for your explanations, but I'm not sure that I well understood
CDillinger wrote:
you have to change the class where your SessionFactory is being built.

Is that mean my class (where my SessionFactory is built) should be in the same directory with hibernate.cfg.xml file, or in my class (where my SessionFactory is built) I have to indicate the path to my hibernate.cfg.xml?
Below, my class is shown, it's found in src/main/java/org/hibernate/tutorial package.
Code:
public class HibernateUtil {
    private static final SessionFactory sessionFactory = buildSessionFactory();

    private static SessionFactory buildSessionFactory(){
        try {
            return new Configuration().configure().buildSessionFactory();
        } catch (Throwable ex) {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }

    public static SessionFactory getSessionFactory() {
        return sessionFactory;
    }

Thank you again.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Wed Feb 24, 2010 7:27 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
new Configuration().configure(xxx).buildSessionFactory();

Right, you can configure the path to you hibernate.cfg.xml where the "xxx" is.


Top
 Profile  
 
 Post subject: Re: hibernate.cfg.xml not found.
PostPosted: Wed Feb 24, 2010 7:56 am 
Newbie

Joined: Mon Feb 22, 2010 4:14 pm
Posts: 4
Thank you very much, it works :)


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