I set up a simple OneToOne display in my entity, but when I save the object, I see that the Select statement is executed by Hibernate just before the insert, and I donβt know why.
@Entity @Table( name = "USER" ) public class NewUser { @OneToOne @JoinColumn(name="user_status_type_id", nullable=false) private UserStatusType userStatusType;
UserStatusType is just a read-only lookup table, so when you save a user, nothing is saved in this table.
User u = new User(); u.setUserStatusType( new UserStatusType(101)); session.persis(u);
But when I save the User object, the output from Hibernate reads like this:
Hibernate: select userstatus_.user_status_type_id, userstatus_.user_status_name as user2_3_ from USER_STATUS_TYPE userstatus_ where userstatus_.user_status_type_id=? Hibernate: insert into USER (created, first_name, last_name, password, user_name, user_status_type_id) values (?, ?, ?, ?, ?, ?)
I do not know if this is normal for Hibernate. I realized that since it was a "persist" operation, I would only see the Insert statement; unsure of the purpose for choosing.
Incorrect display?
source share