org.hibernate.MappingException: invalid configuration

写hibernate的hello world

内容非常简单,一个实体bean--Student.java

一个测试文件--StudentTest.java

两个配置文件:Student.hbm.xml,hibernate.cfg.xml

可是一直报错:

Exception in thread "main" org.hibernate.MappingException: invalid configuration

Caused by: org.xml.sax.SAXParseException; lineNumber: 3; columnNumber: 25; 文档无效: 找不到语法。

我实在是很困惑啊,都简单到不能简单的东西,还报错,也分明知道是配置文件的错,后来又怀疑是jar包的问题,有怀疑是测试写错了。

今天晚上myeclipse突发善心,居然给我很详细的提示,明确指出是hibernate.cfg.xml的第二行出错。

我于是去hibernate的参考文档中把他们的配置文件整个考过来,然后修改,再测试居然华丽丽的通过了。。

果然是hibernate.cfg.xml的文件头出错了。

原来的文件头是:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-configuration

xmlns="http://www.hibernate.org/xsd/hibernate-configuration"

xsi:schemaLocation="http://www.hibernate.org/xsd/hibernate-configuration hibernate-configuration-4.0.xsd"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

修改之后的是:

<?xml version=‘1.0‘ encoding=‘utf-8‘?>

<!DOCTYPE hibernate-configuration PUBLIC

"-//Hibernate/Hibernate Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

结论:

再也不能去其他地方乱考配置文件了,之前的配置文件就是我从一个项目里复制过来的。还是直接去文档里找比较好。

时间: 2024-08-26 16:17:06

org.hibernate.MappingException: invalid configuration的相关文章

hibernate中 org.hibernate.MappingException: invalid configuration 报错

<session-factory>   <!-- #1:基本四项 -->  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/h01</prop

hibernate 出现 org.hibernate.MappingException: entity class not found 的解决办法

在Hibernate 5.0版本以上时,出现异常 org.hibernate.MappingException: entity class not found: 如果确认配置和代码都无误的情况下,可尝试增加一行代码解决: Configuration configuration = new Configuration().configure(); //增加下行代码 configuration.addClass(News.class);

org.hibernate.MappingException: Could not determine type for: java.utils.Date

问题描述 org.hibernate.MappingException: Could not determine type for: java.utils.Date, at table: STUDENTS, for columns: [org.hibernate.mapping.Column(DATE)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:349) at org.hibernate.mapping.Simp

org.hibernate.MappingException: An association from the table order_intem_inf refers to a unmapped

运行一个HIbernate的示例时出现如下错误信息 Exception in thread "main" java.lang.ExceptionInInitializerError at com.hibernate.utils.HibernateUtil.<clinit>(HibernateUtil.java:21) at org.hibernate.samples.PersonManager.main(PersonManager.java:23) Caused by: o

org.hibernate.MappingException: Could not determine type for: java.util.List, at table: user, for...

异常详情: Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: ss_user, for columns: [org.hibernate.mapping.Column(roles)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:336) ~[hibernate-core-4

SSH框架-Caused by: org.hibernate.MappingException: column attribute may not be used together with &lt;column&gt; subelement

昨晚修改了一些表关系,在相关的hbm.xml文件中做了改动,今天早上起来启动tomcat后,发现项目启动不了,控制台报错: 2015-6-14 9:09:42 org.apache.catalina.core.StandardContext listenerStart 严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.Conte

Hibernate 5.X 版本中Exception in thread &quot;main&quot; org.hibernate.MappingException: Unknown entity: cn.xxx.p

最近开始使用最新版本的Hibernate5,所有的配置感觉都正确却还是没有结果. 使用如下: public static void main(String[] args) throws Exception { Configuration cfg = new Configuration().configure(); ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(cfg.get

org.hibernate.MappingException

1.错误描述 org.springframework.beans.factory.BeanCreationException:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:Invocation of init method failed;nested exception is org.hibernate.Mapp

org.hibernate.MappingException: No Dialect mapping for JDBC type: -4

Stacktraces org.hibernate.MappingException: No Dialect mapping for JDBC type: -4 org.hibernate.dialect.TypeNames.get(TypeNames.java:56) org.hibernate.dialect.TypeNames.get(TypeNames.java:81) org.hibernate.dialect.Dialect.getHibernateTypeName(Dialect.