0
私のコードでは以下のエラーが発生します。バッチ更新が更新から予期しない行数を返したためにエラーが発生する
Hibernate: insert into EMPLOYEE (FIRST_NAME, LAST_NAME, SALARY, ID) values (?, ?, ?, ?)
Hibernate: update CERTIFICATE set ID=? where ID=?
org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:81)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:73)
at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:63)
ここは私のコードです。
Employee.java
@Entity
@Table(name="EMPLOYEE")
public class Employee {
@Id
@Column(name="ID")
private int id;
@Column(name="FIRST_NAME")
private String firstName;
@Column(name="LAST_NAME")
private String lastName;
@Column(name="SALARY")
private int salary;
@OneToMany
@JoinColumn(name = "ID")
@OrderBy("name ASC")
private SortedSet<Certificate> certificates;
//getters and setters
}
Certificate.java
@Entity
@Table(name="CERTIFICATE")
public class Certificate implements Comparable <Certificate>{
@Id
@Column(name="ID")
private int id;
@Column(name="CERTIFICATE_NAME")
private String name;
//generate getters and setters
}
私は、コードの下に使用してユーザーを追加しようとしています。
ManageEmployee ME = new ManageEmployee();
/* Let us have a set of certificates for the first employee */
TreeSet set1 = new TreeSet();
set1.add(new Certificate("MCA"));
set1.add(new Certificate("MBA"));
set1.add(new Certificate("PMP"));
/* Add employee records in the database */
Integer empID1 = ME.addEmployee("Manoj", "Kumar", 4000, set1);
と私はコード
Employee employee = new Employee(fname, lname, salary);
employee.setCertificates(cert);
employeeID = (Integer) session.save(employee);
の下に持っている私のaddEmployeeメソッドを持つ私は、これは固定得るために、私の端から変更すべきかを提案してください。
hibernateconfig xmlファイルを共有する – Akshay
'証明書 'エンティティをどのように保存しますか?カスケード '証明書'コレクションが欠けていましたか? –
はここに私hibernateconfig のの の <マッピングクラス= "com.insubuy.model.Address"> <マッピングクラス= "com.insubuy.model.Customer">であります <マッピングクラス= "com.insubuy.model.Policy"> <マッピングクラス= "com.insubuy.model.Employee"> <マッピングクラス= "com.insubuy.model.Certificate"> session-factory> hibernate-configuration> –
Aravind