hibernate 怎么配置id为int的??我查询修改都错
Event.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
SYSTEM
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="com.evens">
<class name="Event" table="EVENTS">
<id name="id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="date" type="timestamp" column="EVENT_DATE" />
<property name="title" column="title" />
</class>
</hibernate-mapping>
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>
<!-- JDBC URL连接mybbs数据库 -->
<property name="connection.url">jdbc:mysql://localhost:3306/event</property>
<!-- 数据库用户名-->
<property name="connection.username">root</property>
<!-- 数据库密码-->
<property name="connection.password">123456</property>
<!-- 各属性的配置-->
<!--为true表示将Hibernate发送给数据库的sql显示出来 -->
<property name="show_sql">true</property>
<property name="current_session_context_class">thread</property>
<!-- SQL方言,这边设定的是MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!--映射文件 -->
<mapping resource="com/evens/Event.hbm.xml" />
</session-factory>
</hibernate-configuration>
Event.java
package com.evens;
import java.util.Date;
/**
* 持久化类
* @author Administrator
*
*/
public class Event {
private int id;
private String title;
private Date date;
public Event(){}
public int getId() {
return id;
}
public void setId(Integer id) {
this.id = id.intValue();
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
}
my.java
package com.evens;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
public class my {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
my m=new my();
// m.add();
// m.load();
// m.list();
// m.update();
m.delete();
}
private void add(){
Event en = new Event();
en.setDate(new Date());
en.setTitle("测试");
Configuration config = new Configuration();
config.configure();
SessionFactory sess = config.buildSessionFactory();
Session session = sess.getCurrentSession();
Transaction tran = session.beginTransaction();
session.save(en);
tran.commit();
}
private void load()
{
Session session=new Configuration().configure().buildSessionFactory().getCurrentSession();