Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3.1.2
Code between sessionFactory.openSession() and session.close():
log.debug("Testing update address...");
user.getAddress().setCountry(new Country("US"));
dao.saveObject(user);
log.debug("Country name is " + user.getAddress().getCountry().getCountryName());
I have two tables:
User (userId, name, addr1, addr2, city, state, countryCode)
Country (countryCode, countryName)
Address is a component class consisting of (addr1, addr2, city, state, country), where country is a class. User to Country is many-to-one. countryCode is the PK for country table.
Country constructor:
Country(final String countryCode) {
this.countryCode = countryCode;
}
The above code executes correctly. It changes the countryCode column of User table to "US". But when I call
user.getAddress().getCountry().getCountryName()
after the update, it returns null. It should hit DB and return the countryName.
If I retrieve the user by userId, then user.getAddress().getCountry().getCountryName() works correctly:
User user = (User) dao.getObject(User.class, new Long(1));
assertNotNull(user);
log.debug("Country name is " + user.getAddress().getCountry().getCountryName());