- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我的领域模型图如下所示:
如您所见,我在 Student 和 Attendance 之间以及 Attendance 和 Seminar 之间建立了一对多关系。
下面是 Student 和 Attendance 类,以及我的帮助类(Initializer)。
package com.seminars.domain;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.GenericGenerator;
import com.seminars.util.SimpleCalendar;
@Entity
@Table(name="Student")
public class Student {
/*start all class fields*/
@Id
//@GenericGenerator(name="kaugen" , strategy="increment")
//@GeneratedValue(generator="kaugen")
@Column(name="studentId")
//@GeneratedValue(strategy=GenerationType.AUTO)
private int studentId;
@Column(name="firstname", length=50, nullable = false)
private String firstname;
@Column(name="lastname", length=50, nullable = false)
private String lastname;
@Column(name="email", length=50, nullable = false)
private String email;
@Column(name="username", length=50, nullable = false)
private String username;
@Column(name="password", length=50, nullable = false)
private String password;
@Column(name="idCard", length=50, nullable = false)
private String idCard;
/* end fields*/
@OneToMany(mappedBy = "student",cascade=CascadeType.ALL)
private Set<Attendance> attendance = new HashSet<Attendance>() ;
/**
* default constructor
*/
public Student(){
}
/**
* Secondary Constructor to automatically create a Student
* @param firstname
* @param lastname
* @param email
* @param username
* @param password
* @param idcard
*/
public Student(String firstname,String lastname,String email, String username,String password, String idcard){
this.setFirstname(firstname);
this.setLastname(lastname);
this.setEmail(email);
this.setIdCard(idcard);
this.setPassword(password);
this.setUsername(username);
}
public int getStudentId() {
return studentId;
}
public void setStudentId(int studentId) {
this.studentId = studentId;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getIdCard() {
return idCard;
}
public void setIdCard(String idCard) {
this.idCard = idCard;
}
/*Methods for connecting Student<------->Attendance*/
/**
* @return a new hashset contain
* <p>all attendances of the student
*/
public HashSet<Attendance> getAttendance(){
return new HashSet<Attendance>(attendance);
}
/**
* @param attendance
* @param seminar
*/
public void addAttendance(Attendance attendance, Seminar seminar){
if(attendance!=null & seminar!=null){
attendance.setStudent(this);
attendance.setSeminar(seminar);
attendance.setRegisterDate((new SimpleCalendar(Calendar.getInstance()))); /* xreiazomaste na orizete I timi apo to sistima automata*/
}
}
/**
* @param attendance to remove from HashSet
*/
public void removeAttendance(Attendance attendance){
attendance.setStudent(null);
}
/**
* @return Attendance HashSet
*/
public Set<Attendance> findAttendance(){
return attendance;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object other) {
if ( other == null) {
return false;
}
if (this == other) {
return true;
}
if (! (other instanceof Student)) {
return false;
}
Student theStudent = (Student) other;
//Integer a=getStudentId();
//Integer b=theStudent.getStudentId();
if(!(getIdCard()==null) ? theStudent.getIdCard()==null : getIdCard().equals(theStudent.getIdCard())){
return false;
}
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return idCard == null ? 0 : idCard.hashCode();
}
}
出勤率
/**
*
*/
package com.seminars.domain;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.junit.Assert;
import org.junit.Test;
import com.seminars.util.SimpleCalendar;
/**
* @author Ilias
*
*/
@Entity
@Table(name = "Attendance")
public class Attendance {
public Attendance() {
this.registerDate=new SimpleCalendar(Calendar.getInstance());
}
@Id
@Column(name="attendanceId")
@GeneratedValue(strategy=GenerationType.AUTO)
private int attendanceId;
@Column(name = "registerDate", length = 200, nullable = false)
//@Temporal(TemporalType.DATE)
@org.hibernate.annotations.Type(
type="com.seminars.persistence.SimpleCalendarCustomType")
private SimpleCalendar registerDate;
@Column(name = "success")
private boolean success;
@ManyToOne
@JoinColumn(name="studentId", nullable = false)
private Student student;
@OneToMany(mappedBy = "attendance",cascade=CascadeType.ALL)
private Set<Absence> absence = new HashSet<Absence>() ;
@ManyToOne
@JoinColumn(name="seminarId", nullable = false)
private Seminar seminar;
@OneToMany(mappedBy = "attendance",cascade=CascadeType.ALL)
private Set<Payment> payment = new HashSet<Payment>() ;/*<<<*/
public SimpleCalendar getRegisterDate() {
return registerDate;
}
public void setRegisterDate(SimpleCalendar registerDate) {
this.registerDate = registerDate;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
/**
* @return the student
*/
public Student getStudent() {
return student;
}
/**
* @param student the student to set
*/
public void setStudent(Student student) {
//this.student = student.findAttendance().add(this);
if (this.student != null) {
this.student.findAttendance().remove(this);
}
this.student = student;
if (this.student != null) {
this.student.findAttendance().add(this);
}
}
/**
* @return the seminar
*/
public Seminar getSeminar() {
return seminar;
}
/**
* @param seminar the seminar to set
*/
public void setSeminar(Seminar seminar) {
//this.student = student.findAttendance().add(this);
if (this.seminar != null) {
this.seminar.findAttendance().remove(this);
}
this.seminar = seminar;
if (this.seminar != null) {
this.seminar.findAttendance().add(this);
}
}
public HashSet<Absence> getAbsence(){
return new HashSet<Absence>(absence);
}
public void addAbsence(Absence absence, SimpleCalendar date){
if(absence!=null && date!=null){
absence.setAttendance(this);
/*stelnoume tin imerominia pou kataxorei I gramamteia oti elipe o foititis*/
absence.setDate(date);
}
}
/**
* @return Absence HashSet
*/
public Set<Absence> findAbsence(){
return absence;
}
/**
* @return HashSet<Payment>
*/
public HashSet<Payment> getPayment(){
return new HashSet<Payment>(payment);
}
public void addPayment(Payment payment, SimpleCalendar date){
if(payment!=null && date!=null){
payment.setAttendance(this);
/*stelnoume tin imerominia pou kataxorei I gramamteia oti elipe o foititis*/
//absence.setDate(date);
}
}
/**
* @return Payment HashSet
*/
public Set<Payment> findPayment(){
return payment;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object other) {
if ( other == null) {
return false;
}
if (this == other) {
return true;
}
if (! (other instanceof Attendance)) {
return false;
}
Attendance theAttendance = (Attendance) other;
//Integer a=getStudentId();
//Integer b=theStudent.getStudentId();
if(!(getStudent()==null) ? theAttendance.getStudent()==null : getStudent().equals(theAttendance.getStudent())){
return false;
}
if(!(getSeminar()==null) ? theAttendance.getSeminar()==null : getSeminar().equals(theAttendance.getSeminar())){
return false;
}
return true;
}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
if(student==null && seminar==null){
return 0;
}
else {
int result=0;
if(student!=null)
result+= 13*getStudent().hashCode()/*+getSeminar().hashCode()*/;
if(seminar!=null)
result+= 13*getSeminar().hashCode();
return result;
}
/*int result = 0;
result = getStudent() == null ? result : 13 * result + getStudent().hashCode();
result = getSeminar() == null ? result : 13 * result + getSeminar().hashCode();
return result; */
}
}
初始化类
package com.seminars.persistence;
import java.util.Calendar;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import com.seminars.domain.Attendance;
import com.seminars.domain.Seminar;
import com.seminars.domain.Student;
import com.seminars.util.SimpleCalendar;
public class Initializer {
/* EntityManager em = DatabaseFactory.createEntityManager();
EntityTransaction tx = em.getTransaction();*/
//delete all data from database
public void eraseData() {
EntityManager em = DatabaseFactory.getCurrentEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Query query = em.createNativeQuery("delete from \"Student\"");
query.executeUpdate();
query = em.createNativeQuery("delete from \"Absence\"");
query.executeUpdate();
query = em.createNativeQuery("delete from \"Attendance\"");
query.executeUpdate();
query = em.createNativeQuery("delete from \"Payment\"");
query.executeUpdate();
query = em.createNativeQuery("delete from \"Seminar\"");
query.executeUpdate();
query = em.createNativeQuery("delete from \"Program\"");
query.executeUpdate();
tx.commit();
em.close();
}
public void prepareData() {
// πριν εισάγουμε τα δεδομένα διαγράφουμε ότι υπάρχει
eraseData();
EntityManager em = DatabaseFactory.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
Student s1=new Student("george","antoniou","antoniougeo@hotmail.com","antoniou","password","998456");
s1.setStudentId(1);
Student s2=new Student("ilias","butsikakis","ili@hotmail.com","ilias","butsi","98756423");
s2.setStudentId(2);
Seminar sem1=new Seminar(1, "Java", 5,500, 2, new SimpleCalendar(2013,1,5), new SimpleCalendar(2013,2,5),"100");
sem1.setSeminarId(1);
Attendance att=new Attendance();
att.setRegisterDate(new SimpleCalendar(Calendar.getInstance()));
//s1.addAttendance(att, sem1);
//s1=em.merge(s1);
//s2=em.merge(s2);
//sem1=em.merge(sem1);
//em.persist(att);
em.persist(s1);
em.persist(s2);
em.persist(sem1);
s1.addAttendance(att, sem1);
em.persist(att);
s1=em.merge(s1);
em.persist(s1);
tx.commit();
em.close();
}
/*public void prepareData1() {
// πριν εισάγουμε τα δεδομένα διαγράφουμε ότι υπάρχει
eraseData();
Student s1=new Student("george","antoniou","antoniougeo@hotmail.com","antoniou","password","998456");
s1.setStudentId(1);
Student s2=new Student("ilias","butsikakis","ili@hotmail.com","ilias","butsi","98756423");
s2.setStudentId(2);
Seminar sem1=new Seminar(1, "Java", 5,500, 2, new SimpleCalendar(2013,1,5), new SimpleCalendar(2013,2,5),"100");
//EntityManager em = DatabaseFactory.createEntityManager();
EntityManager em = DatabaseFactory.createEntityManager();
EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(s1);
em.persist(s2);
tx.commit();
em.close();
/*NOTE ALWAYS REMEMBER:
* 1)Open entity Manager,
* 2)Open Transaction
* 3)Create Items
* else You will need to use merge or you will get a detached exception!!!
* */
//s1=em.merge(s1);
/* Student s1=new Student("george","antoniou","antoniougeo@hotmail.com","antoniou","password","998456");
s1.setStudentId(1);
Student s2=new Student("ilias","butsikakis","ili@hotmail.com","ilias","butsi","98756423");
s2.setStudentId(2);
Seminar sem1=new Seminar(1, "Java", 5,500, 2, new SimpleCalendar(2013,1,5), new SimpleCalendar(2013,2,5),"100");
s1=em.merge(s1);
s2=em.merge(s2);
sem1=em.merge(sem1);
em.persist(s1);
em.persist(s2);
em.persist(sem1);
tx.commit();
em.close();*/
/*EntityManagerFactory emf = Persistence.createEntityManagerFactory("library");
EntityManager em = emf.createEntityManager();*/
//}
}
该项目主要通过 JUnit 测试进行检查,因此在 Initializer 类中,我们有一个 PrepareData 方法,该方法创建一些示例数据以在每次检查中使用,还有一个 delete 方法以确保每次检查都使用相同的数据完成。
在尝试检查 Student 和 Attendance 之间的连接之前,一切似乎都正常。我在初始化程序中创建了一个新的出勤对象,以测试学生是否可以“确定”参加研讨会,但我收到了很多异常消息。
不过,我注意到最多的(如控制台所示)是
3781 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Referential integrity constraint violation: "FKE7E9BF09F9FEB38B: PUBLIC.""Attendance"" FOREIGN KEY(STUDENT) REFERENCES PUBLIC.""Student""(""studentId"")"; SQL statement: delete from "Student" [23003-135]
我检查以确保注释和级联在正确的位置,但没有结果......
我还尝试更改项目在启动器类中的保存顺序,但随后出现其他错误
**javax.persistence.PersistenceException: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.seminars.domain.Attendance.seminar**
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1174)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:674)
at com.seminars.persistence.Initializer.prepareData(Initializer.java:73)
at com.seminars.services.ManageStudentServiceTest.setup(ManageStudentServiceTest.java:60)
at com.seminars.services.ManageStudentServiceTest.testManageStudentService(ManageStudentServiceTest.java:97)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:44)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: com.seminars.domain.Attendance.seminar
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:101)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:130)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:69)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:179)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:135)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:61)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:800)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:774)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:778)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:668)
... 27 more
下面是在初始化类中更改项目顺序之前出现的异常列表:
> javax.persistence.PersistenceException:
> org.hibernate.exception.ConstraintViolationException: could not
> execute native bulk manipulation query at
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235)
> at
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168)
> at
> org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:1245)
> at
> org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:108)
> at
> com.seminars.persistence.Initializer.eraseData(Initializer.java:37)
> at
> com.seminars.services.ManageStudentServiceTest.empty(ManageStudentServiceTest.java:64)
> at
> com.seminars.services.ManageStudentServiceTest.testManageStudentService(ManageStudentServiceTest.java:99)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at
> java.lang.reflect.Method.invoke(Unknown Source) at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
> at
> org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:44)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
> at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
> at
> org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
> at
> org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:220) at
> org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at
> org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: org.hibernate.exception.ConstraintViolationException: could
> not execute native bulk manipulation query at
> org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)
> at
> org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
> at
> org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:219)
> at
> org.hibernate.impl.SessionImpl.executeNativeUpdate(SessionImpl.java:1300)
> at
> org.hibernate.impl.SQLQueryImpl.executeUpdate(SQLQueryImpl.java:365)
> at
> org.hibernate.ejb.QueryImpl.internalExecuteUpdate(QueryImpl.java:183)
> at
> org.hibernate.ejb.AbstractQueryImpl.executeUpdate(AbstractQueryImpl.java:99)
> ... 27 more Caused by: org.h2.jdbc.JdbcSQLException: Referential
> integrity constraint violation: "FKE7E9BF09F9FEB38B:
> PUBLIC.""Attendance"" FOREIGN KEY(STUDENT) REFERENCES
> PUBLIC.""Student""(""studentId"")"; SQL statement: delete from
> "Student" [23003-135] at
> org.h2.message.DbException.getJdbcSQLException(DbException.java:327)
> at org.h2.message.DbException.get(DbException.java:167) at
> org.h2.message.DbException.get(DbException.java:144) at
> org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:378)
> at
> org.h2.constraint.ConstraintReferential.checkRowRefTable(ConstraintReferential.java:395)
> at
> org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:275)
> at org.h2.table.Table.fireConstraints(Table.java:788) at
> org.h2.table.Table.fireAfterRow(Table.java:805) at
> org.h2.command.dml.Delete.update(Delete.java:79) at
> org.h2.command.CommandContainer.update(CommandContainer.java:70) at
> org.h2.command.Command.executeUpdate(Command.java:199) at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdateInternal(JdbcPreparedStatement.java:141)
> at
> org.h2.jdbc.JdbcPreparedStatement.executeUpdate(JdbcPreparedStatement.java:127)
> at
> org.hibernate.engine.query.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:210)
> ... 31 more
您能帮我确定为什么会出现这些错误吗?我尝试了我能想到的一切,但收效甚微。任何帮助将不胜感激。
最佳答案
您试图在删除出勤率之前从数据库中删除所有学生。但是出勤率对学生有外键。因此,如果数据库允许您删除学生,您将拥有一个不连贯的数据库:引用不存在的学生的出勤率。
因此您必须先删除出勤,然后再删除学生。
请注意,实体之间存在的级联是无关紧要的,因为插入、更新和删除查询完全忽略它们。
关于java - JPA参照完整性约束违反oneToMany和批量操作查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20276817/
这是我在阅读了几个关于 jpa 批量插入的主题后创建的简单示例,我有 2 个持久对象用户和站点。一个用户可以有多个站点,所以我们在这里有一对多的关系。假设我想创建用户并将多个站点创建/链接到用户帐户。
我有文档列表(对象),该对象有多个文档,即存在 Json 记录,但是当我尝试上传文档束(记录)时,它没有上传到文档数据库,但当我上传单个文档记录时,它上传成功。 List listObj = ne
我希望进行批量域名查找,看看是否有一些域名可供购买。我找不到 perl 模块,但似乎应该有一种方法可以在 perl 中执行此操作。我正在寻找免费的东西。谢谢! 最佳答案 从这里:http://www.
我制作了一个批处理类来检查 FTP 上的文件、下载它们并在 FTP 上删除它们。 当我手动运行它(不是批量运行)时,它运行完美,下载 FTP 中的所有文件并在下载完成后删除它们。 当我尝试批量运行时,
我有一个 *+* 形式的字符串 base。我想得到+之前的所有内容。例如,如果 base=foo+bar,我想获取 foo。 我尝试过使用字符串替换来实现 set left=%base:+*=% 但这
我需要创建几十个表,并且我需要它们是innodb, 有没有办法做到这一点,而不是将 engine=innodb 附加到每个 create table 语句? 最佳答案 可以在服务器级别指定默认引擎,在
我正在尝试制作显示 unix/linux 提示符的 dos shell。代码是: @echo off :hi set tmpdrv=%cd:~0,2% if %homedrive% == %tmpdr
我有以下代码,基本上是在二维矩阵的每一行上进行一维卷积。卷积核是一样的。所以真的是 SIMD 案例。 a = [ 1,2,3,4,5; 6,7,8,9,7; 7,6
情况: 我尝试在 shell 中的循环内移动文件,但我的代码无法正常工作。 for /D %%F in (*) do ( if "%%F" NEQ "%directoryToPutFilesIn
目录包含 2 个(或更多)任意名称的视频文件。 video1.mkv video2.mkv 需要找出每个视频的持续时间。为此,我们使用 MediaInfo . setlocal EnableDelay
如何在 Windows 中批量删除数千个文件中的空格(而不是替换为下划线)?我可以从 DOS 命令执行此操作吗? 目前: file one.mp3 file two.mp3 所有文件需要变成: fil
我想创建一个批处理文件,它读取 2 个不同的值,并根据它们的比较方式进行相应处理。但是,比较永远不会起作用。代码是: REM string1 and string2 contain the follo
我正在尝试将一个文件夹的子文件夹复制到许多其他名称未知的文件夹中。目的是在所有使用它的员工文件夹中备份程序的源文件。如果在员工文件夹中找不到程序文件夹,则不应执行任何操作。这看起来如下: 来源: F:
我正在寻找一种简单的方法来检测一小段文本(几句话)是否为英语。在我看来,这个问题比尝试检测任意语言要容易得多。有没有可以做到这一点的软件?我正在用 python 编写,并且更喜欢 python 库,但
我们正在尝试向 8k 种不同的设备发送促销推送消息。我们正在成功响应推送通知 URL https://fcm.googleapis.com/fcm/send 但只有部分用户收到此通知,并非全部。那么
基本上我只是用这一段来替换我的 var 中的一个字符串,但我无法让嵌套延迟扩展正常工作。这甚至可能吗? set replace=!replace:!search!=!replaceVal!! 我知道执
如何使用 ffmpeg 对一批视频文件进行编码,使用相同的设置? 我找到了 one-line solution将当前文件夹中的 .avi 文件转换为 .mov。请注意,我要编码 .mov -> .mo
我正在尝试制作一个批处理文件,每次循环时都会将变量增加 1,然后检查变量是否等于 5,如果不是,则再次循环。我知道这可能有一个 while 循环,但我不知道如何做到这一点,我现在只是享受学习 Batc
我正在尝试创建一个循环,读取多个 CSV 文件,这些文件都具有相同类型的气温数据。但是,我想跳过数据上方的行。这些是数据集中的“警报”。每个文件可能有不同数量的警报,因此要跳过不同数量的行。见下文:
因此,我正在批量创建一个Mail程序,而消息传递部分出现了问题。 消息传递部分是无限循环。 当我输入多个单词时,它会崩溃。 这是代码。请帮忙! :rep set line= set /p line=
我是一名优秀的程序员,十分优秀!