实体类packagecom.tao.pojo;public classStudent {privateString id;privateString name;privateString pass;publicStudent() {super();
}publicStudent(String name, String pass) {super();this.name =name;this.pass =pass;
}publicStudent(String id, String name, String pass) {super();this.id =id;this.name =name;this.pass =pass;
}publicString getId() {returnid;
}public voidsetId(String id) {this.id =id;
}publicString getName() {returnname;
}public voidsetName(String name) {this.name =name;
}publicString getPass() {returnpass;
}public voidsetPass(String pass) {this.pass =pass;
}
@OverridepublicString toString() {return "Student [id=" + id + ", name=" + name + ", pass=" + pass + "]";
}
}
映射文件<?xml version="1.0"?>
/p>
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
配置文件<?xml version="1.0" encoding="UTF-8"?>
/p>
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
com.mysql.jdbc.Driver
root
jdbc:mysql://localhost:3306/test0228_002
root
org.hibernate.dialect.MySQLDialect
true
true
update
测试packagecom.tao.test;importorg.hibernate.Session;importorg.hibernate.SessionFactory;importorg.hibernate.cfg.Configuration;importorg.hibernate.dialect.MySQL5Dialect;public classTestMain {//用hibernate框架创建表
public static voidmain(String[] args) {
Configuration configure= new Configuration().configure("hibernate.cfg.xml");
SessionFactory factory=configure.buildSessionFactory();
Session session=factory.openSession();
session.beginTransaction();
session.getTransaction().commit();
session.close();
factory.close();
}
}
用程序生成表,如果报的有这个错
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versionfor the right syntax to use near ‘type=MyISAM‘ at line 6解决方案
将数据库方言改为org.hibernate.dialect.MySQL5Dialect