What went wrong? When I looked at generated table the filed type for classid was LOB while I expected it to be an int (It just an ID from foreign key). The culprit is -using column instead of joincolumn
1
2
3
4
5
6
7
8
9
10
| public class StudentDetails implements Serializable{ @OneToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE},fetch = FetchType.EAGER) @Column(name="classid") private ClassDetails classId;Instead of column, it should be join column @OneToOne(cascade={CascadeType.REFRESH,CascadeType.MERGE},fetch = FetchType.EAGER) @JoinColumn(name="classid",nullable=false) <strong> See the joincolumn </strong> private ClassDetails classId;} |
If join column is not specified, JPA assumes that ClassDetails object will be saved (along with its all nested graph) to DB and hence it creates a LOB type -telling it that its a joined foreign key resulted in a int data type for the field.
Please read full article from Data truncation exception while joining one to one in JPA
No comments:
Post a Comment