이 문제를 해결하기 위해 테스트했지만 2 일이 지나면 아무것도 작동하지 않습니다. 나는이 엔티티들을 양방향 관계로 암시했다.Hibernate "ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Duplicate entry"해결 방법 예외
@Service
public class UIServiceImpl implements UIService {
@Autowired
private TinfosProfileRepository infosProfileRepository;
@Override
public T_infosProfile saveInfosPorfile(T_user connectedUser){
T_infosProfile infosProfile = connectedUser.getInfosProfile();
infosProfile.setUser(connectedUser);
connectedUser.setInfosProfile(infosProfile);
try {
return infosProfileRepository.save(infosProfile);
} catch (Exception e) {
throw new ExceptionsDAO(e.getMessage());
}
}
하지만이 메소드를 호출 할 때 한 상황에 있지만 작동 : 나는 또한 사용자의 infosProfile 업데이트하는 데 사용되는이 방법이
@Entity
@Table(name = "T_infosProfile")
public class T_infosProfile {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id_infos;
@OneToOne(targetEntity = T_user.class, fetch = FetchType.LAZY)
@JoinColumn(name = "id_user", unique = true, nullable = false)
private T_user user;
@Column(name = "pourcentage_completion", length = 3, updatable = true, unique = false)
private Integer pourcentageCompletion;
@Column(name = "infos_identite", nullable = false, updatable = true, length = 1, columnDefinition = "TINYINT(1)")
private Boolean infosIdentiteCompleted;
@Column(name = "infos_coordonnees", nullable = false, updatable = true, length = 1, columnDefinition = "TINYINT(1)")
private Boolean infosCoordonneesCompleted;
@Column(name = "infos_bancaires", nullable = false, updatable = true, length = 1, columnDefinition = "TINYINT(1)")
private Boolean infosBancaireCompleted;
@Column(name = "infos_chicowa", nullable = false, updatable = true, length = 1, columnDefinition = "TINYINT(1)")
private Boolean infosCompleted;
//the setter method
public void setUser(T_user user) {
this.user = user;
this.infosIdentiteCompleted = true;
this.pourcentageCompletion = 0;
this.infosCoordonneesCompleted = this.user.getInfosCoordonnees() == null ? false : true;
this.infosBancaireCompleted = this.user.getInfosBancaire() == null ? false : true;
this.infosCompleted = this.user.getInfosCompleted() == null ? false : true;
if (this.infosCoordonneesCompleted == true) {
this.pourcentageCompletion = 50;
}
if (this.infosBancaireCompleted == true && this.pourcentageCompletion == 50) {
this.pourcentageCompletion = 75;
}
if (this.infosChicowaCompleted == true && this.pourcentageCompletion == 75) {
this.pourcentageCompletion = 100;
}
}
}
@Entity
@Table(name = "T_user")
public class T_user implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id_user;
@OneToOne(targetEntity = T_infosProfile.class, mappedBy = "user", fetch = FetchType.LAZY, orphanRemoval = true)
private T_infosProfile infosProfile;
public void setInfosProfile(T_infosProfile infosProfile) {
this.infosProfile = infosProfile;
}
}
그리고
또 다른 하나는 예외가 있습니다 :10-04-2017 16:27:43 [http-nio-8080-exec-3] WARN o.h.e.jdbc.spi.SqlExceptionHelper - SQL Error: 1062, SQLState: 23000
10-04-2017 16:27:43 [http-nio-8080-exec-3] ERROR o.h.e.jdbc.spi.SqlExceptionHelper - Duplicate entry '8' for key 'UK_bkariaocmnn2rlh477hvoqkyf'
현재 사용자의 infosProfile 속성 만 업데이트하려고합니다. 하나의 infosProfile 속성 만 업데이트되었지만 동시에 2 개의 속성을 업데이트하고 saveInfosProfile()을 시도하면 예외가 발생합니다.
도움주세요.
내가 알고 있지만 난 그냥 기존 개체를 저장 볼 수 있듯이 나는이 예외가 발생 왜 내가 모르는 새로운 인스턴스를 생성하지 않는
. – akuma8
당신은 무엇을 의미합니까? "당신이 제약 조건을 생성하는 동안 이름을 지정하지 않으면 그 일이 일어납니다." – akuma8
@ akuma8, 시스템 생성시 읽을 수없는 제약 조건 이름이 나타납니다. – Rahul