When I fetching the object from the collection i am getting the TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: com.report.Object2.obj3 -> com.report.Object3
Below is my object structure:
@Table( name = "TAB1" )
Class Object1 {
... fields
@OneToMany( mappedBy = "field", fetch = FetchType.LAZY )
private List<Object2> obj2List;
}
@Table( name = "TAB2" )
Class Object2 {
... fields
@ManyToOne
@JoinColumn( name = "J_ID", referencedColumnName = "J_ID" )
private Object3 obj3;
}
@Table( name = "TAB3" )
Class Object3 {
... fields
@Column( name = "J_ID" )
private Long jId;
}
Note: I am not inserting any records with this. It is only getting the records from DB.
So, I am fetching the Object1 from DB and i am taking the Object3 from list of Object2s. When I call the getter of the Object3 from Object2, I am getting this exception.
Please suggest me if I am missing somthing here and Why this exception occurs.
Thanks in advance.