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.  [ 2 posts ] 
Author Message
 Post subject: Initial SessionFactory creation failed.org.hibernate.Hiberna
PostPosted: Fri Aug 18, 2006 11:26 am 
Newbie

Joined: Fri Aug 18, 2006 6:47 am
Posts: 11
I am running eclipse 3.2, and I am trying to run the first example through eclipse, i have included all the libraries in the project, everything builds and compiles fine, however when i go to run the main method of eventmanager i get the error beloew:

The file structure is the same as the example in the tutorial that is in the /doc/reference/tutorial. I have even made a copy of it under:
/src/util.

I even tried to manually change:
sessionFactory = new Configuration().configure("hibernate.cfg.xml").buildSessionFactory();

so that it looks locally but it still doesnt work, what else do i need to do?

Also how do i integrate it with tomcat 5.5?

Hibernate version: 3

Code between sessionFactory.openSession() and session.close():

nitial SessionFactory creation failed.org.hibernate.HibernateException: hibernate.cfg.xml not found
Exception in thread "main" java.lang.ExceptionInInitializerError
at src.util.HibernateUtil.<clinit>(HibernateUtil.java:17)
at src.users.EventManager.createAndStoreEvent(EventManager.java:42)
at src.users.EventManager.main(EventManager.java:15)
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:1287)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1309)
at src.util.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 2 more


[b]Microsoft SQL Server 2005b]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 19, 2006 8:53 pm 
Beginner
Beginner

Joined: Sat Aug 19, 2006 8:04 pm
Posts: 30
hi

your hibernate.cfg.xml has to be in the class path, if you're running tomcat that's ${project_dir}/WEB-INF/classes

so i'm not sure where you have it, but you need to get it in there one way or another. the problem is, eclipse doesn't show this folder, and everytime you clean your project the classes dir gets erased. so you'll be copying that file over a lot.

the solution i came up with was to make a sepearte conf dir, and put all my config files in there. then use an ant build script to copy all those files to classes everytime i build.

here's my build.xml, modify to suit your needs (don't expect it to run without going through it first). in eclipse there's a number of ways to run it. right click it -> run as -> ant build. or you can go project -> properties -> builders and set it up in there, however i find it to be a pain this way as you may just want to let eclipse compile your files automatically, and just run this when you change some hibernate related stuff.

Code:
<!--     Ant build file for a tomcat project with hibernate.
            Uses xdoclet to generate the mapping files and schema export to
            create the tables.

        Set the project name and the project.name in the next two lines.     -->

<project name="dosimetry" default="build">
    <property name="project" value="dosimetry" />

    <property name="conf.dir" value="conf" />
    <property name="web-inf.dir" value="WEB-INF" />
    <property name="classes.dir" value="${web-inf.dir}/classes" />
    <property name="lib.dir" value="${web-inf.dir}/lib" />
    <property name="src.dir" value="${web-inf.dir}/src" />

    <!-- value="/usr/local/tomcat/common/lib" /> -->
    <property name="tomcat.lib.dir" value="c:/tomcat/common/lib" />

    <path id="project.classpath">
        <pathelement location="${classes.dir}" />
        <fileset dir="${lib.dir}">
                <include name="**/*.jar" />
        </fileset>
        <pathelement location="${tomcat.lib.dir}/servlet-api.jar" />
        <pathelement location="${tomcat.lib.dir}/jasper-runtime.jar" />
        <pathelement location="${tomcat.lib.dir}/jsp-api.jar" />


        <pathelement location="${basedir}/../Hibernate/classes" />
        <pathelement location="${basedir}/../DisplayTag/classes" />
    </path>

    <target name="configure.eclipse" if="eclipse.running">
        <property name="build.compiler"
                        value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <echo message="Configuring compiler for Eclipse..."/>
    </target>

<!-- clean the project's output dir and
        delete the schema export file -->
    <target name="clean">
        <delete>
            <fileset dir="${classes.dir}">
                <exclude name="log4j.properties" />
                <include name="**/*" />
            </fileset>
        </delete>
    </target>

<!-- compile the project -->
    <target name="compile">
        <antcall target="configure.eclipse" />
        <javac srcdir="${src.dir}"
                    destdir="${classes.dir}"
                    classpathref="project.classpath" />
    </target>

<!-- clean, compile -->
    <target name="copyClasses" depends="compile">
        <copy todir="${classes.dir}" preservelastmodified="true">
            <fileset dir="${src.dir}">
                <exclude name="**/*.java" />
            </fileset>
        </copy>
    </target>

<!-- compile, and use xdoclet to generate the .hbm.xml files -->
    <target name="generate-hbm" depends="compile">
        <taskdef name="hibernatedoclet"
                    classname="xdoclet.modules.hibernate.HibernateDocletTask"
                    classpathref="project.classpath"  />
        <property file="${conf.dir}/hibernate.properties" />
        <hibernatedoclet destdir="${classes.dir}"
                                verbose="true">
            <fileset dir="${src.dir}">
                <include name="**/*.java" />
            </fileset>
            <hibernate version="3.0" />
            <hibernatecfg dialect="${hibernate.dialect}"
                                jdbcUrl="${hibernate.connection.url}"
                                driver="${hibernate.connection.driver_class}"
                                userName="${hibernate.connection.username}"
                                password="${hibernate.connection.password}"
                                showSql="true"
                                version="3.0" />
        </hibernatedoclet>
    </target>

<!-- copy all those files in conf to class dir -->
    <target name="copyConf">
        <copy todir="${classes.dir}" preservelastmodified="false">
            <fileset dir="${conf.dir}" />
        </copy>
    </target>

<!-- copy any dependecies (other projects) over -->
    <target name="copyDep">
        <copy todir="${classes.dir}" preservelastmodified="true">
            <fileset dir="${basedir}/../Hibernate/classes" />
            <fileset dir="${basedir}/../DisplayTag/classes" />
        </copy>
    </target>

<!-- generate the mapping documents and use schema export to create the tables -->
    <target name="schema-export" depends="generate-hbm">
        <taskdef name="schemaexport"
                    classname="org.hibernate.tool.hbm2ddl.SchemaExportTask"
                    classpathref="project.classpath" />
        <schemaexport quiet="no"
                            output="${conf.dir}/schema-export.sql"
                            properties="${conf.dir}/hibernate.properties">
            <fileset dir="${classes.dir}">
                <include name="**/*.hbm.xml"/>
            </fileset>
        </schemaexport>
    </target>

<!-- clean, compile, build, generate-hbm, schema-export -->
    <target name="build"
                depends="clean, compile, copyClasses,
                                generate-hbm, copyConf, copyDep" />

</project>


hope that helps


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