Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:3
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:MySQL 4.1
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
Hi,
I have mapped one-to-many relationship as follows:
[User 1<--->*UserI18nAddress]
User user = new User();
user.setAddresses(new HashMap());
UserI18nAddress address = new UserI18nAddress();
address.setAddress("whatever");
user.getAddresses().put("english", address);
entityManager.persist(user);
After executing the above code from sesssion bean, the user instance is persisted, and the address also persisted correctly (and the user_id is populated in the child table correctly too), however, the languageId(which is the key of the address) in the child table was ignored. While the expected that hibernate will set the languageId to "english" in the users_i18n_addresses record table. The following is excerpt of the entities classes.
@Entity
@Table(name="users")
public class User {
..........................................
private Map<String,UserI18nAddress> addresses=null;
@OneToMany(cascade = CascadeType.ALL)
@JoinColumn(name="user_id")
@MapKey(name="languageId")
public Map<String,UserI18nAddress> getAddresses() {
return addresses;
......................
}
@Entity
@Table(name="users_i18n_addresses")
public class UserI18nAddress {
private User user=null;
@ManyToOne
@JoinColumn(name="user_id")
public User getUser() {
return user;
}
................
}
Is it a bug ? or am I mistaken ?
Regards,
Zaid