此问题困扰笔者很久,希望能帮到一些初学者。
先不多说了,初学Hibernate框架写了一个Demo,结果一直运行不出来想要的结果。
先描述下环境:在eclipse中添加了Hibernate的插件,然后使用的是Hibernate-4.3.11版本。数据库使用的是MySQL5.5.28。在数据库中先创建好一个数据库名字叫:hibernate,里面没有任何东西。
下面首先贴出我的项目列表和文件代码,以及错误
以下是每个文件的具体代码
News.java文件代码如下
package com.hibernate.pojo;
import java.sql.Date;
public class News {
private Integer id;
private String title;
private String author;
private Date date;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public News(String title, String author, Date date) {
super();
this.title = title;
this.author = author;
this.date = date;
}
public News() {}
@Override
public String toString() {
return "News [id=" + id + ", title=" + title + ", author=" + author
+ ", date=" + date + "]";
}
}
hibernate.cfg.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>
<!-- 配置数据库新型 -->
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
<property name="connection.username">root</property>
<property name="connection.password">root</property>
<!-- 配置hibernate基本信息 -->
<!-- 配置数据库方言 -->
<property name="dialec