各位大虾,本人在开发EJB项目的时候出现一个问题,我们分成了两个ejb项目,其中一个ejb项目中的Menu表和另一个EJB项目的Tip表有多对一关系,两个项目分别打包到对方,放入jboss下运行出现以下错误。
org.hibernate.AnnotationException: @OneToOne or @ManyToOne on menu.tip references an unknown entity: tip
menu.java:@Entity
@Table(name="menu")
public class menu {
private static final long serialVersionUID = 2320547167861415034L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id; //用户编号(主键)
@Column
private String account; //登录帐号
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
@ManyToOne(cascade=CascadeType.REFRESH, optional=true)
@Basic(fetch=FetchType.LAZY)
@JoinColumn(name = "tip_id")
private tip tip; //与Role对象多对一关联 public tip getTip() {
return tip;
}
public void setTip(tip tip) {
this.tip = tip;
}}tip.java:
@Entity
@Table(name="tip")
public class tip {
private static final long serialVersionUID = 2320547167861415034L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Integer id; //用户编号(主键)
@Column
private String account; //登录帐号
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
@OneToMany(mappedBy = "tip", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private Set<menu> menus; // 与User对象一对多关联 public Set<menu> getMenus() {
return menus;
}
public void setMenus(Set<menu> menus) {
this.menus = menus;
}} 
请问两个Ejb项目之间的表实现关联应该怎么做,google了下说jvm的classLoader有关,请大虾们赐教~

解决方案 »

  1.   

    @OneToMany(mappedBy = "tip", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "menuId")
    private Set<menu> menus; // 与User对象一对多关联 public Set<menu> getMenus() {
    return menus;
    }
    这样?
      

  2.   

    1对多关系中,1的表不用加入外键的,所以2楼的仁兄这个方法不行,主要是因为两个ejb项目之间如何实现关联的问题,坐等大牛解释。
      

  3.   

    hibernate的注解放在属性定义上有时好使,最好放在get方法上