저장된 객체의 참조를 포함 할 때 JPA를 사용하여 객체를 저장할 수 없습니다 사용자 테이블의 기본 키최대 절전 모드 :이다 userprofileid가 포함되어 아래에 명시된 목적은 내가 userprofileId</p> <p>고용주 테이블을 포함하는 스키마 고용주 테이블이
id int(11) (not NULL) PRI
userprofileid int(11) (not nUll)
organization_name varchar(50) (not nUll)
이제이 고용주를위한 JPA 클래스를 작성해야했습니다.
이제 우리는 아래 항목과 함께 Employer.java를 갖게되었습니다.
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToOne(fetch=FetchType.LAZY,cascade = CascadeType.ALL)
@JoinColumn(name="userProfileId", referencedColumnName="id")
@Column(insertable=false ,updatable =false)
private UserProfile userProfile;
@Column(name = "organization_name")
private String organizationName;
이제 장애물이 있습니다. UserProfile은 다른 방법으로 생성 된 개체입니다. 이제는 userprofile 테이블에 동일한 값을 다시 추가하고 싶지 않아서 employer.java에 insertable = false 및 updatable = false를 작성하여 필드가 업데이트되지 않도록했습니다. 내가 고용주 객체의 사용자 프로필의 값을 설정하면
아니오
는
org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.hcentive.core.user.UserProfile; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.hcentive.core.user.UserProfile
를 말합니다하지만 난 설정 해달라고하면 사용자는 오류가 아래에 있습니다 프로필. 내가 사용하고 계속 발생에 대한
Caused by: java.sql.SQLException: Field 'userprofileid' doesn't have a default value
참고 :
getJpaTemplate().persist(t);