我有StudentGroup.class:
package com.grades.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
@Entity
@Table(name = "StudentGroup", uniqueConstraints = { @UniqueConstraint(columnNames = "group_number") })
public class StudentGroup {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "group_number")
private int groupNumber;
public StudentGroup() {
}
public StudentGroup(int groupNumber) {
this.groupNumber = groupNumber;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getGroupNumber() {
return groupNumber;
}
public void setGroupNumber(int groupNumber) {
this.groupNumber = groupNumber;
}
@Override
public String toString() {
return "StudentGroup [id=" + id + ", groupNumber=" + groupNumber + "]";
}
}
在我的数据库中,我有一个名为“ student_group”的表,当我尝试使用休眠插入一行时,在Tomcat中收到以下异常:SEVERE:Servlet [mvc-dispatcher]的Servlet.service(),路径为[/应用程序]引发异常[请求处理失败;嵌套的异常是org.hibernate.exception.SQLGrammarException:无法插入:[com.grades.model.StudentGroup]],其根本原因是
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'db.studentgroup'不存在
有人可以帮我解决这个问题吗?
最佳答案
此“ @Table(name =“ StudentGroup”“)表示您的数据库表应命名为“ StudentGroup”,并相应地更改注释或表名。