springside4多对多映射

山头的兄弟 发布于 2013/04/12 16:01
阅读 118
收藏 0

@Table(name = "acct_user")

public class User extends IdEntity {

@ManyToMany(cascade=CascadeType.ALL,targetEntity =Menu.class)
@JoinTable(name="acct_user_menu",joinColumns=@JoinColumn(name="user_id",referencedColumnName="id"),inverseJoinColumns=@JoinColumn(name="menu_id",referencedColumnName="id"))
public List<Menu> getOrders(){
return orders;
}
public void setOrders(List<Menu> orders){
this.orders=orders;
}
}

@Entity
@Table(name="menu")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Menu extends IdEntity{

 private Set<User> users = new HashSet<User>();
    
    @ManyToMany (mappedBy="orders",cascade = {CascadeType.ALL })
    public Set<User> getUsers(){
    return users;
    }

}

在controller中代码 user.setOrders(orders 中间表没 反应 

加载中
返回顶部
顶部