Hibernate 无法在OneToMany关系上确定关系属性的目标实体

Hibernate 无法在OneToMany关系上确定关系属性的目标实体,hibernate,jpa,netbeans,netbeans-7,Hibernate,Jpa,Netbeans,Netbeans 7,我有NetBeans 7.4在创建RESTFul web服务时生成的实体类代码。 当我测试webservice时,我得到以下异常 The target entity of the relationship attribute [emps] on the class [class test.Dept] cannot be determined. When not using generics, ensure the target entity is defined on the rel

我有NetBeans 7.4在创建RESTFul web服务时生成的实体类代码。 当我测试webservice时,我得到以下异常

 The target entity of the relationship attribute [emps] on the class 
 [class test.Dept] cannot be determined.  When not using generics, ensure 
 the target entity is defined on the relationship mapping.
Emp实体

@Entity
@Table(name="EMP"
    ,schema="SCOTT"
)@XmlRootElement

public class Emp  implements java.io.Serializable {

@ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="DEPTNO")
    public Dept getDept() {
        return this.dept;
    }
部门实体

@Entity
@Table(name="DEPT"
    ,schema="SCOTT"
)@XmlRootElement

public class Dept  implements java.io.Serializable {

@OneToMany(fetch=FetchType.LAZY, mappedBy="dept")
    public Set getEmps() {
        return this.emps;
    }
冬眠。复仇

<?xml version="1.0" encoding="UTF-8"?>    
<hibernate-reverse-engineering>
  <schema-selection match-schema="SCOTT"/>
  <table-filter match-name="EMP"/>
  <table-filter match-name="DEPT"/>
</hibernate-reverse-engineering>
 <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property 
    name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <mapping class="test.Emp"/>
    <mapping class="test.Dept"/>
  </session-factory>

hibernate.cfg

<?xml version="1.0" encoding="UTF-8"?>    
<hibernate-reverse-engineering>
  <schema-selection match-schema="SCOTT"/>
  <table-filter match-name="EMP"/>
  <table-filter match-name="DEPT"/>
</hibernate-reverse-engineering>
 <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.OracleDialect</property>
    <property 
    name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property>
    <mapping class="test.Emp"/>
    <mapping class="test.Dept"/>
  </session-factory>

org.hibernate.dialen.oraclealent
oracle.jdbc.OracleDriver

EMP关系不能提供足够的信息来确定目标实体。您有两种简单的方法来提供此信息

A) 仿制药 使用泛型(可能意味着一些重构):

C) 目标属性
谢谢,第一种方法非常有效。我尝试了第二种方法,得到的错误
Emp.class不是ElementType
,因为某种原因
@Target
对我和guy都不起作用。我们必须使用
targetEntity
属性。是否可能
@Target
仅对所示的
@Embedded
有效?
@OneToMany(fetch=FetchType.LAZY, mappedBy="dept", targetEntity=Emp.class)
public Set getEmps() {
    return this.emps;
}