newEntity1
이라는 엔티티가 포함 가능한 클래스 Leaverequest
에 있습니다. 엔티티 클래스에서 Collectionofelements
을 사용하고 있지만 다음과 같은 예외가 발생합니다. 아무도 그게 무슨 뜻인지 설명해 주시겠습니까?예외 : 키 'PRIMARY'에 대한 '1- x01'중복 항목
예외
Caused by: java.sql.BatchUpdateException: Duplicate entry '1-\x01' for key 'PRIMARY'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2028)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1451)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 8 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1-\x01' for key 'PRIMARY'
법인 :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.treamis.entity;
import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import org.hibernate.annotations.CollectionOfElements;
/**
*
* @author hyva
*/
@Entity
public class NewEntity1 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@CollectionOfElements
private Set<LeaveAppliedDetails> leaveAppliedDetails = new LinkedHashSet<LeaveAppliedDetails>();
@Override
public String toString() {
return "com.treamis.entity.NewEntity1[ id=" + id + " ]";
}
public Set<LeaveAppliedDetails> getLeaveAppliedDetails() {
return leaveAppliedDetails;
}
public void setLeaveAppliedDetails(Set<LeaveAppliedDetails> leaveAppliedDetails) {
this.leaveAppliedDetails = leaveAppliedDetails;
}
public boolean addLeaveAppliedDetails(LeaveAppliedDetails e) {
return leaveAppliedDetails.add(e);
}
}
테스터 등급 :
NewEntity1 newEntity = new NewEntity1();
LeaveAppliedDetails lad=new LeaveAppliedDetails();
lad.setHalfDay(true);
newEntity.addLeaveAppliedDetails(lad);
LeaveAppliedDetails lad1=new LeaveAppliedDetails();
lad1.setHalfDay(true);
newEntity.addLeaveAppliedDetails(lad1);
Session s=HibernateUtil.getSessionFactory().openSession();
s.save(newEntity);
s.beginTransaction().commit();
LeaveAppliedDetails에 대한 코드도 제공해야합니다. 나는 그 엔티티를 저장할 때 문제가 발생했다고 생각한다. – TondaCZE