(初学)hibernate问题,急救! Exception in thread "main" org.hibernate.InvalidMappingException: Un

Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:109)
at org.hibernate.cfg.Configuration.add(Configuration.java:478)
at org.hibernate.cfg.Configuration.add(Configuration.java:474)
at org.hibernate.cfg.Configuration.add(Configuration.java:647)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:730)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:2109)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:2081)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2061)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2014)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1929)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1908)
at Test.Test.main(Test.java:18)
Caused by: org.dom4j.DocumentException: Error on line 16 of document : Content is not allowed in trailing section. Nested exception: Content is not allowed in trailing section.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.internal.util.xml.MappingReader.readMappingDocument(MappingReader.java:78)
... 11 more

hibernate4.14版本的

hibernate.cfg.xml如下
<!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>

<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/hibernate_4.1.4_tset</property>
<property name="hibernate.connection.username">jiebo</property>
<property name="hibernate.connection.password">1234</property>

<mapping resource="moder/po/User.hbm.xml"/>
</session-factory>
</hibernate-configuration>

User.hbm.xml如下:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="moder.po.User" table="Users">
<id name="id" column="id">
<generator class="native"></generator>
</id>

<property name="name" column="name"/>
<property name="password" column="password"/>
</class>

</hibernate-mapping>>
Test类
package Test;

import moder.po.User;
import org.hibernate.Session;import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class Test { public static void main(String[] args) {

Configuration cfg=new Configuration();
cfg=cfg.configure();

SessionFactory factory=cfg.buildSessionFactory();
Session session=factory.openSession();
Transaction tx=session.beginTransaction();

User user=new User();

user.setName("dsd");
user.setPassword("454");
session.save(user);
tx.commit();
}

}

第1个回答  2013-03-13
hbm.xml文件有问题呗,你把那个多余的空格什么的去掉,整理好那映射文件看看
第2个回答  2013-07-05
我的也是这个问题正在努力解决呢 命苦啊
Hibernate 4.1.4

Configuration config = new Configuration().configure();
ServiceRegistry registry = new ServiceRegistryBuilder().applySettings(config.getProperties()).buildServiceRegistry();
SessionFactory sf = config.buildSessionFactory(registry);
第3个回答  2013-03-12
缺少文件包
第4个回答  2016-01-26
多半是废了

...main" org.hibernate.InvalidMappingException: Unable to read XM...
Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML at org.hibernate.util.xml.MappingReader.readMappingDocument(MappingReader.java:101)...Caused by: org.dom4j.DocumentException: Error on line 2 of document : The processing instruction target matching "[...

Hibernate报错:Exception in thread "main" org.hibernate.HibernateEx...
这是告诉你mysql方言找不到,说明你相关的jar包没有导入,这个方言是在hibernate核心jar包内的rg.hibernate.dialect包中,你自己看一下自己的里边有没有。如果你确定你的包导入正确的话,那就是你单词大小写写错了,我看了下你的这个错误,应该是你的类写错了:MYSQLDialect这个类中的Y应该是小写的y。

Exception in thread "main" org.hibernate.MappingException: Un...
return Object.class;} 你在使用泛型DAO的时候,采用的是直接使用泛型DAO类:HibernateGenericDao<Users> dao = new HibernateGenericDao<Users>();所以,这个dao的类型仍然是HibernateGenericDao;使用getGenericSuperclass()方法得到的就是这个类的父类,Object;所以你直接返回了一个Object.class,注意,为...

MyEclipse运行时出现Access denied for user ''root''@'localhost' (u...
数据库用Navicat打的开,求大神帮忙具体错误信息如下:Exceptioninthread"main"org.hibernate.exception.GenericJDBCException:Cannotopenconnectionatorg.hibernate.exception.SQLSt... 数据库用Navicat打的开,求大神帮忙具体错误信息如下:Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open co...

求Hibernate大神解决问题,Exception in thread "main" java.lang.Excep...
删掉class文件重新编译,或者重启编译工具

求Hibernate大神解决问题,Exception in thread "main" java.lang.Excep...
String configFile="hibernate.cfg.xml";\/\/hibernate配置文件的路径 Configuration config=new Configuratioin();config.configure(configFile);...

Exception in thread "main" java.lang.ExceptionInInitializerError at...
所以你由Configuration得到的Session就是个null。你首先看看你的hibernate的配置文件是不是叫hibernate.cfg.xml如果叫这个那你就要把它放到src目录里。这是容器默认的读取这个文件的方式,如果你的文件不叫这个,那好。在读取文件的时候把这个文件的所在标好。否则还是找不到。推荐第一种方式!

如下错误:org.hibernate.exception.GenericJDBCException: Could n...
我刚才也遇到了,是数据库的字符集和表的字符集与你代码字符集不匹配,改为一样即可

Exception in thread "main" org.springframework.beans.factory.Bean...
xml文件里你把sessionFactory 内容写错了吧 Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml] 提示你这 创建的 bean有问题

...not initialize class com.demo.hibernate.util.HibernateSessionFacto...
我也出现过这种情况,但是每次解决的方法都不一样 1:有可能是有一个什么ant3.2(记得不清楚反正在前面几个中)的包多了,删除就可以了 2:记得有一次我删除了也不管用,结果重新写一下程序就好了 3:还有就是在hibernate的配置文件里面写错什么东西了 ...

相似回答