发生PersistenceException:org.hibernate.exception.ConstraintViolationException:无法执行JDBC批处理更新

发生PersistenceException:org.hibernate.exception.ConstraintViolationException:无法执行JDBC批处理更新,hibernate,jdbc,playframework,playframework-1.x,Hibernate,Jdbc,Playframework,Playframework 1.x,我有一个Play Framework 1.2.7应用程序,其中包含两个模型、课程和部门。 系有许多课程,课程属于一个系。当我试图创建一个部门时,出现了此错误,PersistenceException:org.hibernate.exception.ConstraintViolationException:无法执行JDBC批更新 这是我的课程模型 package models; import javax.persistence.Entity; import javax.persistence.L

我有一个Play Framework 1.2.7应用程序,其中包含两个模型、课程和部门。 系有许多课程,课程属于一个系。当我试图创建一个部门时,出现了此错误,
PersistenceException:org.hibernate.exception.ConstraintViolationException:无法执行JDBC批更新

这是我的课程模型

package models;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
public class Course extends Model {
public String CourseName;
public String CourseCode;

@Lob
public String CourseDescription;

@ManyToOne
public Department department;
public Course(String CourseName, String CourseCode, String CourseDescription, Department department){
    this.CourseName = CourseName;
    this.CourseCode = CourseCode;
    this.CourseDescription = CourseDescription;
    this.department = department;
}
}
这是我的部门模型

package models;

import java.util.List;

import javax.persistence.Entity;
import javax.persistence.OneToMany;

import play.db.jpa.Model;

@Entity
public class Department extends Model {
String DepartmentName;
String DepartmentCode;

@OneToMany
List<Course> courses;

public Department(String DepartmentName, String DepartmentCode){
    this.DepartmentName = DepartmentName;
    this.DepartmentCode = DepartmentCode;
}
public void addCourse(Course course){
    this.courses.add(course);
    this.save();
}
}
封装模型;
导入java.util.List;
导入javax.persistence.Entity;
导入javax.persistence.OneToMany;
导入play.db.jpa.Model;
@实体
公共课系扩展模式{
字符串DepartmentName;
字符串部门代码;
@独身癖
列出课程;
公共部门(字符串部门名称、字符串部门代码){
this.DepartmentName=部门名称;
this.DepartmentCode=部门代码;
}
公共课程(课程){
本.课程.添加(课程);
这是save();
}
}

最近的更新​​您的类没有影响您的数据库。 您必须删除类中的变量。代码是正确的,但数据库中的数据不必自动更新。这就是为什么你会有这个错误。 作为解决方案:打开表中给定的数据库部门&课程将删除超出的列

我对博士后已经有这个问题了


注:我的英语不太正确,因为我使用谷歌翻译。

显示创建和保存记录的代码。事实上,我是这样做的。我删除了数据库并创建了一个新的数据库,代码中没有任何更改,它工作正常。很难理解你的意思。我不确定这个答案是否有用。