nordborg wrote:
...
Just tried out
session.refresh(object)
This makes the current session aware of changes to the database:
Code:
User user4 = (User) session.get(User.class, 8);
System.out.println("Username: " + user4.getUsername());
System.out.println("Press key to continue...");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s = br.readLine();
session.refresh(user4);
System.out.println("Username: " + user4.getUsername());
Output after updating username to 'quaqua' while program waited for user input:
Code:
Hibernate: select user0_.ID as ID0_0_, user0_.username as username0_0_, user0_.password as password0_0_, user0_.title as title0_0_, user0_.firstname as firstname0_0_, user0_.lastname as lastname0_0_, user0_.email as email0_0_, user0_.account_id as account8_0_0_ from USERS user0_ where user0_.ID=?
Username: user1
Press key to continue...
Hibernate: select user0_.ID as ID0_1_, user0_.username as username0_1_, user0_.password as password0_1_, user0_.title as title0_1_, user0_.firstname as firstname0_1_, user0_.lastname as lastname0_1_, user0_.email as email0_1_, user0_.account_id as account8_0_1_, products1_.user_id as user1_3_, product2_.ID as product2_3_, product2_.ID as ID3_0_, product2_.name as name3_0_, product2_.price as price3_0_ from USERS user0_ left outer join USER_PRODUCTS products1_ on user0_.ID=products1_.user_id left outer join PRODUCTS product2_ on products1_.product_Id=product2_.ID where user0_.ID=?
Username: quaqua