-->
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.  [ 1 post ] 
Author Message
 Post subject: Failed to create Session Factory
PostPosted: Wed Jan 16, 2013 11:17 am 
Newbie

Joined: Wed Jan 16, 2013 11:06 am
Posts: 1
Hi Forum,

ich hoffe ihr könnt mir helfen ich Suche jetzt schon seit zwei Tagen nach einer Lösung für mein Problem ich bin mir auch nicht hunder prozent sicher ob es ein hibernate Problem ist oder Problem mit einer der anderen beteiligten Platformen.

Zur Problem Stellung ich habe eine kleine H2-database laufen auf welcher ich mit Java und Hibernate das Data-Access-Tier realisiere. Als IDE verwende ich Eclipse JUNO zur Kommunikation wird JWebSocket(http://jwebsocket.org/) genommen. Ein Android Handy schickt Token an die Hibernate Schicht welche eine Transaktion auf der Datenbank ausführt. Das blöde ist jetzt nur wenn ich das ganze aus Eclipse starte funktioniert es einwandfrei. Sobald ich das ganze jedoch als Jar exportiere bekomme ich folgenden Fehler:

Failed to create sessionFactory object.org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml

Meine hibernate.cfg.xml sieht folgendermaßen aus:
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>

Beispielhaft 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>


Die Erstellung der Session funktioniert über die HibernateUtil.class:
Code:
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;
    }
}

Vielen Dank schonmal für die Hilfe :)
Youza


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.