我真的需要你的帮助。
我是新的休眠。试图保存一个对象,但所有时间我都收到错误:
引起:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'hibernate.person'不存在
这是域对象:
@Table(name = "Person")
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private String id;
@Column(name = "Person_age")
private int age;
@Column(name = "Person_name")
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
这是我的hibernate配置文件:
<?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>
<!-- Database connection settings -->
<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">******</property>
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- Show all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Drop and re-create the database schema on startup -->
<property name="hbm2ddl.auto">create</property>
<!-- Mapping files -->
<mapping class="ua.macko.domain.Person" />
</session-factory>
</hibernate-configuration>
我得到的错误是:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.person' doesn't exist
。
我试图设置hbm2ddl.auto参数来创建和更新,但这没有给我任何结果。
请告诉我,我做错了什么?
Thnx提前
答案 0 :(得分:0)
添加javassist库后问题已解决。感谢大家的帮助!
答案 1 :(得分:-1)
<property name="hbm2ddl.auto">create</property>
hibernate.cfg.xml
错误,请使用
<property name="hibernate.hbm2ddl.auto">create</property>
代替。