hibernate报错:Could not parse mapping document from resource

hibernate配置文件
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd
">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">
org.postgresql.Driver
</property>
<property name="hibernate.connection.url">
jdbc:postgresql://localhost:5432/myspace
</property>
<property name="hibernate.connection.username">postgres</property>
<property name="connection.password">123456</property>
<property name="hibernate.dialect">
org.hibernate.dialect.PostgreSQLDialect
</property>
<property name="show_sql">true</property>
<mapping resource="com/java/hibernate/User.hbm.xml" />
</session-factory>
</hibernate-configuration>

User影射文件
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd
">
<hibernate-mapping>
<class name="User">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<property name="password"/>
<property name="regDate"/>
<property name="loginTimes"/>
</class>
</hibernate-mapping>

User类文件
package com.java.hibernate;

import java.util.Date;

public class User {
private long id;
private String name;
private String password;
private Date regDate;
private int loginTimes;

public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getRegDate() {
return regDate;
}
public void setRegDate(Date regDate) {
this.regDate = regDate;
}
public int getLoginTimes() {
return loginTimes;
}
public void setLoginTimes(int loginTimes) {
this.loginTimes = loginTimes;
}
}
最新回答
孤则酒灌

2024-09-13 18:41:19

楼上说的有道理,补充一下:如果你只想在class节点中的name属性的值为User,那么在hibernate-mapping节点中你应该加一个package属性,应该写成<hibernate-mapping package = "com.java.hibernate">。在class节点中的table属性的值是代表你数据库中对应的表,如果你不写这个属性的话,那你的数据库中应该有一张名为User的表,不然的话,你就必须告诉程序你的持久化类关系的那张表。并且在property节点中的column属性是代表这个User对象中某个变量对应数据库中的某一列。如果不写的话,那你的表中的字段必须和你的User中的成员变量的名字一一对应。否者必须要写,并且变量和表的列的关系要映射清楚。
雨点躲日落

2024-09-13 03:06:20

整了一天了,就是这个问题,看了N篇解答,最后也没解决,
最后在hibernate配置文件里把数据库的方言换了一下,终于好使了,哎,hibernate!!!
想你想到脑子短路

2024-09-13 18:33:21

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"
http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd
">
<hibernate-mapping>
<class name="com.java.hibernate.User" table="study" schema="dbo" catalog="student">
<id name="id" type="java.lang.Integer" column="id">
<generator class="native"/>
</id>
<property name="name" type="java.lang.String"/>
<property name="password" type="java.lang.String"/>
<property name="regDate" type="java.lang.Date"/>
<property name="loginTimes" type="java.lang.String"/>
</class>
</hibernate-mapping>
</hibernate-mapping>
在数据库中建立一个study数据库名 看看测试结果有没有student表
继续逞强

2024-09-13 04:02:35

<property name="connection.password">123456</property>
应该为:
<property name="hibernate.connection.password">123456</property>
「遺落的星星」

2024-09-13 19:47:31

配置文件问题!~