티스토리 뷰
SW개발/Hibernate
org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.cidog.concreteinfo.mo del.CiClst
개소왕 2018. 7. 7. 08:04org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: 클래스명
* 원인
A클래스가 B에 대한 FK 를 가지고 있음. (OneToOne)
SELECT FROM A
WHERE A.B_ID = ?
실행시
Restrictions.eq("B_ID", B객체) 해야 함.
B객체를 ID값만 임의 지정한 임시객체를 만들어서 넣었기 때문이었음.
* 해결
B객체를 DB로부터 직접 불러와서 사용
( ex : Restrictions.eq("B_ID", findB(B의ID)) )
* 다른 해결책
@OneToOne(cascade=CascadeType.ALL) 지정하라는 의견
- Cascade 쓰고 싶지 않아서 적용하지 않음
* 참고 : Cascade
- 위의 예시에서 기능을 사용한다면,
save(A) 하게 되면
A가 가지고 있는 B객체도 함께 저장하게 됨.
'SW개발 > Hibernate' 카테고리의 다른 글
@ElementCollection 지정된 개체, 저장 후 기존 데이터 사라지는 현상 (0) | 2018.07.11 |
---|---|
org.hibernate.id.enhanced.TableStructure - could not read a hi value (0) | 2018.07.09 |
Hibernate / java.lang.ClassCastException: java.math.BigInteger cannot be cast to java.lang.Long (0) | 2018.06.07 |
다중 트랜잭션 매니저 (0) | 2018.05.24 |
javax.persistence.TransactionRequiredException: Executing an update/delete query (0) | 2018.05.21 |