-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: mapped collection is not working
PostPosted: Wed May 31, 2006 10:51 am 
Newbie

Joined: Tue Jan 04, 2005 4:05 am
Posts: 8
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.