初学hibernate,运行时出现这个问题,望大虾们指点一二.对于你们来说应该不难吧。我不会么。java编写的
log4j:WARNNoappenderscouldbefoundforlogger(org.hibernate.cfg.Environment).log4j:WARNP...
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource SS/SS.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at util.HibernateUtil.main(HibernateUtil.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:555)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 7 more
Caused by: org.dom4j.DocumentException: C:\hibernates\http:\hibernate.sourceforge.net\hibernate-mapping-3.0.dtd (系统找不到指定的路径。) Nested exception: C:\hibernates\http:\hibernate.sourceforge.net\hibernate-mapping-3.0.dtd (系统找不到指定的路径。)
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)
... 8 more
出现了这么多错误,我就被无语了。望大虾们看看。应该就是配置问题吧。 展开
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.InvalidMappingException: Could not parse mapping document from resource SS/SS.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
at util.HibernateUtil.main(HibernateUtil.java:13)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:555)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
... 7 more
Caused by: org.dom4j.DocumentException: C:\hibernates\http:\hibernate.sourceforge.net\hibernate-mapping-3.0.dtd (系统找不到指定的路径。) Nested exception: C:\hibernates\http:\hibernate.sourceforge.net\hibernate-mapping-3.0.dtd (系统找不到指定的路径。)
at org.dom4j.io.SAXReader.read(SAXReader.java:484)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:546)
... 8 more
出现了这么多错误,我就被无语了。望大虾们看看。应该就是配置问题吧。 展开
展开全部
document from resource SS/SS.hbm.xml
这个文件找不到吧,要不就是配置错了
给个完整的配置给你,一定要看清路径哦,建路径的时候注意
<?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">
<hibernate-configuration>
<session-factory><!-- url -->
<property name="connection.url">
jdbc:mysql://localhost:3306/outman
</property>
<!-- 用户名 -->
<property name="connection.username">root</property>
<!-- 密码 -->
<property name="connection.password">root</property>
<!--驱动类 -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- 指明方言类 表示连接的数据库名称oracle,mysql之类的-->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- 控制台输出SQL语句 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="myeclipse.connection.profile">mysql</property>
<!-- 映射文件的路径 -->
<mapping resource="org/outman/domain/account.xml" />
</session-factory>
</hibernate-configuration>
<!-- 映射文件 -->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.outman.domain">
<class name="Account" table="t_account">
<id name="id" type="integer" column="id">
<generator class="native" />
</id>
<component name="name" class="Name">
<property name="firstName" column="t_first_name"
type="string" />
<property name="lastName" column="t_last_name"
type="string" />
</component>
<property name="phone" column="t_phone" type="string" />
</class>
</hibernate-mapping>
<!--类文件-->
public class Account implements java.io.Serializable {
private Integer id;
private Name name;
private String phone;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Name getName() {
return this.name;
}
public void setName(Name name) {
this.name = name;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
create database outman;
ues outman;
create table t_account (
id integer not null auto_increment,
t_first_name varchar(255),
t_last_name varchar(255),
t_phone varchar(255),
primary key (id)
);
这个文件找不到吧,要不就是配置错了
给个完整的配置给你,一定要看清路径哦,建路径的时候注意
<?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">
<hibernate-configuration>
<session-factory><!-- url -->
<property name="connection.url">
jdbc:mysql://localhost:3306/outman
</property>
<!-- 用户名 -->
<property name="connection.username">root</property>
<!-- 密码 -->
<property name="connection.password">root</property>
<!--驱动类 -->
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<!-- 指明方言类 表示连接的数据库名称oracle,mysql之类的-->
<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- 控制台输出SQL语句 -->
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="myeclipse.connection.profile">mysql</property>
<!-- 映射文件的路径 -->
<mapping resource="org/outman/domain/account.xml" />
</session-factory>
</hibernate-configuration>
<!-- 映射文件 -->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.outman.domain">
<class name="Account" table="t_account">
<id name="id" type="integer" column="id">
<generator class="native" />
</id>
<component name="name" class="Name">
<property name="firstName" column="t_first_name"
type="string" />
<property name="lastName" column="t_last_name"
type="string" />
</component>
<property name="phone" column="t_phone" type="string" />
</class>
</hibernate-mapping>
<!--类文件-->
public class Account implements java.io.Serializable {
private Integer id;
private Name name;
private String phone;
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
public Name getName() {
return this.name;
}
public void setName(Name name) {
this.name = name;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
}
create database outman;
ues outman;
create table t_account (
id integer not null auto_increment,
t_first_name varchar(255),
t_last_name varchar(255),
t_phone varchar(255),
primary key (id)
);
展开全部
这个很简单:2点
1、配置数据库的时候用户名和密码没有写对
2、没有导入相应数据库的驱动JAR包
把你的配置文件发一下,我帮你解决!我的邮箱是rorywei@yeah.net
希望我的回答能够帮到您!
看了你的配置了,你的数据库名字和密码是root和qq168么???
还有 你引入的是mysql-connector-java
你有mysqldriver.jar这个包么???
1、配置数据库的时候用户名和密码没有写对
2、没有导入相应数据库的驱动JAR包
把你的配置文件发一下,我帮你解决!我的邮箱是rorywei@yeah.net
希望我的回答能够帮到您!
看了你的配置了,你的数据库名字和密码是root和qq168么???
还有 你引入的是mysql-connector-java
你有mysqldriver.jar这个包么???
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你最好先用默认的hibernate。hbm。xml, 这个测试通了在修改默认配置文件。否则很难确定是你的配置文件放错地方了还是配置内容出的错。
不过你这里貌似不是路径问题,应该是配置出问题了,
你的错误提示是说不能解析映射,而且下边也是提示:你的解析映射的dtd说找不到,那就明确了,你的xml头部配置有问题。你改成像一楼的那样,直接从网上获取dtd,
你报的是mapping,那应该是这个:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
应该就没问题了。。
不过你这里貌似不是路径问题,应该是配置出问题了,
你的错误提示是说不能解析映射,而且下边也是提示:你的解析映射的dtd说找不到,那就明确了,你的xml头部配置有问题。你改成像一楼的那样,直接从网上获取dtd,
你报的是mapping,那应该是这个:
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN "
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd ">
应该就没问题了。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
遇到这种一堆的错误不用着急,一个一个来嘛 ,先看看SS/SS.hbm.xml,在源码路径下找,有吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询