emmanuel wrote:
did you try?
I did some time ago, but had no time to post last week,
With @ManyToOne(fetch-lazy),
@org.hibernate.annotations.Entity(dynamicUpdate=true, selectBeforeUpdate=false):
1) it did a first lookup and it loaded the eager members + the foreign key
2) update simply updated the login field. PERFECT
Is there any step to remove the select statement on the annotated line (see code)?
Code:
Session session = factory.getSession();
Transaction tx = session.beginTransaction();
Car car = new Car();
car.setName("beetle");
session.save(car);
User user = new User();
user.setName("name");
user.setPassword("old");
user.setLogin("old");
user.setCar(car);
session.save(user);
tx.commit();
System.out.println("User and car saved");
session.clear();
// tries to update leaving relation as it was
tx = session.beginTransaction();
User loaded = (User) session.load(User.class, user.getId());
// QUESTION HERE
// it would be great if setLogin would not select before update...
// is it possible?
loaded.setLogin("newlogin");
session.update(loaded);
tx.commit();
System.out.println("User updated");
session.clear();
// tries to update leaving relation as it was
tx = session.beginTransaction();
User found = (User) session.load(User.class, user.getId());
System.out.println("Found user " + found.getLogin());
System.out.println("His car is " + found.getCar().getName());
tx.commit();
generates
Code:
Hibernate: insert into Car (id, name) values (null, ?)
Hibernate: call identity()
Hibernate: insert into User (id, car_id, login, password, name) values (null, ?, ?, ?, ?)
Hibernate: call identity()
User and car saved
Hibernate: select user0_.id as id2_0_, user0_.car_id as car5_2_0_, user0_.login as login2_0_, user0_.password as password2_0_, user0_.name as name2_0_ from User user0_ where user0_.id=?
Hibernate: update User set login=? where id=?
User updated
Hibernate: select user0_.id as id2_0_, user0_.car_id as car5_2_0_, user0_.login as login2_0_, user0_.password as password2_0_, user0_.name as name2_0_ from User user0_ where user0_.id=?
Found user newlogin
Hibernate: select car0_.id as id0_0_, car0_.name as name0_0_ from Car car0_ where car0_.id=?
His car is beetle
So the question in the topic has been solved, now Im moving for a "selectBeforeUpdate" question in the same topic... should I open another one?
Thanks again...