比如现在有一个Account类代表一个用户,我们的用户可以有多个好友。代码如下: public class Account{
String id ; String userName; String password; List<Account> friends;
....getter/setter }
现在应该怎么映射这种一对多的关系呢?请各位帮忙。
freebox
2008-08-31 02:11
一对多注释语法@OneToMany 在这个问题里应该是个多对多的关系吧?
javaEE
2008-08-31 10:23
恩是的。多谢。但是具体怎么映射呢?这个应该是双向多对多的关系。 public class Account{
@ManyToMany List<Account> friends;
}
这时候另一端也是Account,那么怎么映射。谢谢。
[该贴被javaEE于2008-08-31 10:25修改过]
freebox
2008-08-31 11:09
就这么的就行了吧?
javaEE
2008-08-31 11:27
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, at table: Account, for columns: [org.hibernate.mapping.Column(friends)] 这样会抛出这个异常。不知道改怎么写,请帮忙呵呵。多谢了。