使用ExportDB.java自动生成数据库表时出错,错误如下:
Exception in thread "main" java.lang.NoSuchFieldError: name
at org.slf4j.impl.Log4jLoggerAdapter.(Log4jLoggerAdapter.java:75)
at org.slf4j.impl.Log4jLoggerFactory.getLogger(Log4jLoggerFactory.java:75)
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:103)
at org.hibernate.cfg.Configuration.(Configuration.java:151)
at com.test.drp.test.ExportDB.main(ExportDB.java:11)
数据库为oracle 10g
ExportDB.java代码如下:
import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
public class ExportDB {
public static void main(String[] args) {
//读取配置文件
Configuration cfg = new Configuration().configure();
//创建SchemaExport对象
SchemaExport export = new SchemaExport(cfg);
//创建数据库表
export.create(true,true);
}
}
People.java代码如下:
public class People {
private int id;
private String name;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
People.hbm.xml代码如下:
<?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的配置文件中加入
hibernate.hbm2ddl.auto="update/create-drop/create"