Initial SessionFactory creation failed.org.hibernate.MappingException: could not instantiate id generator
在网上找了很多Hibernate的相关教程,大多数都是结合WEB服务器的,自己写一个单独
的示例在Eclipse下直接运行,不需要自己写ANT脚本,不需要结合web服务器。但是需要MYSQL数据库-_-
首先要学会如何使用Eclipse,然后要下载Hibernate需要的所有JAR文件,最后安装好MYSQL
准备开始!
第一步,我们要创建一个表 结构如下
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | MUL | NULL | auto_increment |
| title | varchar(400) | YES | | NULL | |
| content | text | YES | | NULL | |
| time | datetime | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
第二步,在Eclipse中创建一个JAVA项目(我在项目中用到的包名是cn.com.nick.hbm)。编写News.java类,这个类对应了数据库中的表
package cn.com.nick.hbm;
import java.util.Date;
public class News
{
private int id;
private String title;
private String content;
private Date date;
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getTitle()
{
return title;
}
public void setTitle(String title)
{
this.title = title;
}
public String getContent()
{
return content;
}
public void setContent(String content)
{
this.content = content;
}