2014-09-24 3 views
0

Я пытаюсь создать простой проект спящего режима, но я получаю сообщение об ошибке при чтении файла hibernate.cfg.xml, не знаю, в чем проблема, ниже - это трассировка кода и ошибок. Пожалуйста помоги.Ошибка загрузки спящего режима

Вот мой hibernate.cfg.xml файл:

<?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> 
     <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/EPS</property> 
     <property name="hibernate.connection.username">haris</property> 
     <property name="hibernate.connection.password">ihatecookies</property> 

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

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

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

     <!-- Drop or re-create database --> 
     <property name="hibernate.hbm2ddl.auto">update</property> 

     <!-- Mapping files --> 
     <mapping class="com.secure.eps.model.User"/>   

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

Вот мой основной класс:

package com.secure.eps.controller; 

import org.hibernate.Session; 
import org.hibernate.SessionFactory; 
import org.hibernate.boot.registry.StandardServiceRegistry; 
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; 
import org.hibernate.cfg.Configuration; 

import com.secure.eps.model.User; 

public class HibernateUtil { 

    public static void main(String args[]){ 

     User user = new User(); 
     user.setUsername("RoojiPooji"); 
     user.setPassword("ihatecookies"); 

     Configuration configuration = new Configuration().configure("hibernate.cfg.xml"); 
     StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build(); 
     SessionFactory sessionFactory = configuration.configure().buildSessionFactory(serviceRegistry); 

     Session session = sessionFactory.openSession(); 
     session.beginTransaction(); 
     session.save(user); 
     session.getTransaction().commit(); 
     session.close(); 

    } 

} 

Вот стек ошибка:

Sep 24, 2014 9:37:41 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit> 
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final} 
Sep 24, 2014 9:37:41 PM org.hibernate.Version logVersion 
INFO: HHH000412: Hibernate Core {4.3.6.Final} 
Sep 24, 2014 9:37:41 PM org.hibernate.cfg.Environment <clinit> 
INFO: HHH000205: Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.h2.Driver, hibernate.service.allow_crawling=false, hibernate.dialect=org.hibernate.dialect.H2Dialect, hibernate.max_fetch_depth=5, hibernate.format_sql=true, hibernate.generate_statistics=true, hibernate.connection.username=sa, hibernate.connection.url=jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1;MVCC=TRUE, hibernate.bytecode.use_reflection_optimizer=false, hibernate.jdbc.batch_versioned_data=true, hibernate.connection.pool_size=5} 
Sep 24, 2014 9:37:41 PM org.hibernate.cfg.Environment buildBytecodeProvider 
INFO: HHH000021: Bytecode provider name : javassist 
Sep 24, 2014 9:37:41 PM org.hibernate.cfg.Configuration configure 
INFO: HHH000043: Configuring from resource: hibernate.cfg.xml 
Sep 24, 2014 9:37:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream 
INFO: HHH000040: Configuration resource: hibernate.cfg.xml 
Exception in thread "main" org.hibernate.HibernateException: Could not parse configuration: hibernate.cfg.xml 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2163) 
    at org.hibernate.cfg.Configuration.configure(Configuration.java:2075) 
    at com.secure.eps.controller.HibernateUtil.main(HibernateUtil.java:19) 
Caused by: org.dom4j.DocumentException: null Nested exception: null 
    at org.dom4j.io.SAXReader.read(SAXReader.java:484) 
    at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2155) 
    ... 2 more 

ответ

0

Я считаю, что это проблема с этой строкой в ​​вашей конфигурации xml.

<!-- Mapping files --> 
    <mapping class="com.secure.eps.model.User"/> 

См зимовать документы: http://www.tutorialspoint.com/hibernate/hibernate_mapping_files.htm.

+0

Нет, это не так, вы можете также отобразить объект внутри файла конфигурации гибернации. –

+0

Попробуйте удалить строку, переданную в метод Configuration.configure(). По умолчанию он должен искать ресурс приложения «hibernate.cfg.xml». Дайте мне знать, как это происходит! – proulxs

+0

его все тот же. –

Смежные вопросы