Just embarking on this Hibernate journey here.
If I have a column that is defined like so
Code:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="USER_ID")
private Long userId;
and the application logic looks like so
Code:
Session session = HibernateUtil.getSessionFactory().openSession();
session.getTransaction().begin();
User user = new User();
//set various properties of user
session.save(user);
I can see that if I inspect the value of the user instance right after the save it has the value of the id that was just inserted. So is hibernate doing a "SELECT" from the database right after the INSERT to retrieve that value?
But reading the manual I get the impression that if there are other columns in the table that are populated by means of triggers or some such, then I need to do a session.refresh() so the user instance has those properties.
And one related question
Is there anything to choose between these two statements
Code:
User justInsertedUser = (User)session.get(User.class, user.getUserId());
and
Code:
session.refresh(user);
Thanks!