hibernate Session -> Session Factory failed

youza

Erfahrenes Mitglied
Liebe Leute ich dreh durch,

Bei hibernate habe ich eine kleine H2 Datenbank im Hintergrund laufen und setzt mit Hibernate und Java das DataAccessTier auf.
In Eclipse funktioniert alles wie gewünscht sobald ich die JAR aber exportiere bekomme ich den Fehler
Code:
Failed to create sessionFactory object.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

Dieser Fehler tritt wie gesagt nur auf wenn ich die Jar extern starte.
Und jetzt mal zu allen Informationen im Projekt (bin auch nicht sicher in welchem Forum des am besten passt):
Es baut auf einen JWebSocket Version 1.0.8 welcher für die Kommunikation zuständig ist über eine Android Handy wird ein Token gesandt welcher dann eine Transaktion über hibernate auf die H2 database auslöst. Funktioniert wenn ich den JWebSocket aus Eclipse starte super allerdings nicht mehr wenn ich die Jar exportiere und dann im JWebSocket einbinde -> obwohl die einbindung genau so funktioniert wie in Eclipse auch.

hibernate.cfg.xml:
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>

        <!-- Database connection settings -->
        <property name="connection.driver_class">org.h2.Driver</property>
        <property name="connection.url">jdbc:h2:tcp://localhost/~/TrafficSignValidation</property>
        <property name="connection.username">sa</property>
        <property name="connection.password"></property>

        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>

        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.H2Dialect</property>

        <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>

        <!-- Disable the second-level cache  -->
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>

        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">update</property>
	    
	    <mapping resource="com/gigatronik/tsvalid/dto/Position.hbm.xml"/>
	    <mapping resource="com/gigatronik/tsvalid/dto/Probability.hbm.xml"/>
	    <mapping resource="com/gigatronik/tsvalid/dto/TypCategory.hbm.xml"/>
	    <mapping resource="com/gigatronik/tsvalid/dto/TSType.hbm.xml"/>    
	    <mapping resource="com/gigatronik/tsvalid/dto/Trafficsign.hbm.xml"/>
	    <mapping resource="com/gigatronik/tsvalid/dto/StrCategory.hbm.xml"/>
	    <mapping resource="com/gigatronik/tsvalid/dto/Street.hbm.xml"/>

    </session-factory>
</hibernate-configuration>


Mit dieser Klasse erzeuge ich die SessionFactory:
Java:
package com.gigatronik.tsvalid.logic;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

public class HibernateUtil {
	private static ServiceRegistry serviceRegistry;
	private static SessionFactory sessionFactory = buildSessionFactory();

	public static SessionFactory buildSessionFactory() {
		try {
			Configuration cfg = new Configuration().configure();

			serviceRegistry = new ServiceRegistryBuilder().applySettings(
					cfg.getProperties()).buildServiceRegistry();
			sessionFactory = cfg.buildSessionFactory(serviceRegistry);
//			sessionFactory =  new Configuration().configure().buildSessionFactory();/**/
		} catch (Throwable ex) {
			System.err.println("Failed to create sessionFactory object."
					+ ex);
			throw new ExceptionInInitializerError(ex);
		}
		return sessionFactory;
	}
}

exemplarisch noch die Position.hbm.xml
Code:
<?xml version = "1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.gigatronik.tsvalid.dto">
    
	<class name="Position" table="T_POSITION" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" select-before-update="false" optimistic-lock="version">
		<id name="id" column="PK_POSID">
            <generator class="sequence">
                <param name="sequence">SEQ_POSITION</param>
            </generator>
        </id>
        
		<property name="longitude"  type="double" column="LONGITUDE" update="true" unique="false" optimistic-lock="true" lazy="false" generated="never" /> 
		<property name="latitude"  type="double" column="LATITUDE" update="true" unique="false" optimistic-lock="true" lazy="false" generated="never" /> 
		<property name="altitude"  type="double" column="ALTITUDE" update="true" unique="false" optimistic-lock="true" lazy="false" generated="never" /> 
	
	</class>
</hibernate-mapping>

Also ich weiß echt nicht mehr weiter und würde mich über Hilfe super freuen :)
 
Zurück