当我尝试保存新的“用户”时,我一直收到此错误。 当我列出我的数据库“test”中记录的“用户”时,我没有问题
这是我的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="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/test</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.format_sql">false</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<mapping class="test.model.Users"/>
</session-factory>
</hibernate-configuration>
这是我的Users.java:
package test.model;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="users")
public class Users implements Serializable {
private static final long serialVersionUID = 1L;
private Integer id;
private String login;
private String name;
private String password;
private String access;
private String status;
public Users() {
}
public Users(String login, String name, String password, String access, String status) {
this.login = login;
this.name = name;
this.password = password;
this.access = access;
this.status = status;
}
@Id
@Column(name="id", unique=true, nullable=false)
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
@Column(name="login", nullable=false, length=20)
public String getLogin() {
return this.login;
}
public void setLogin(String login) {
this.login = login;
}
@Column(name="name", nullable=false, length=50)
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@Column(name="password", nullable=false, length=50)
public String getPassword() {
return this.password;
}
public void setPassword(String password) {
this.password = password;
}
@Column(name="access", nullable=false, length=15)
public String getAccess() {
return this.access;
}
public void setAccess(String access) {
this.access = access;
}
@Column(name="status", nullable=false, length=10)
public String getStatus() {
return this.status;
}
public void setStatus(String status) {
this.status = status;
}
}
我的朋友哪里错了?
答案 0 :(得分:1)
可能由于这个原因发生了错误:
<mapping class="test.Users"/>
正如我所见,您的用户&#39; class位于&#39; test.model&#39;包,而不仅仅是测试&#39;
尝试通过以下方式更改映射:
<mapping class="test.model.Users"/>
祝你好运