我有一个实体,其中有一个字段表示使用embeddeid注释的复合主键,另一个字段使用嵌入式注释进行注释。 这两个字段都不会直接映射到传递给createNativeQuery方法的查询返回的列。 getResultList返回实体列表,但我提到的两个字段在所有实体中都为null。
public interface Key{
public int hashCode()
}
@Embeddable
public class CompositePK impements Key{
private int empid;
private Date startdate;
private Date enddate;
}
@Embeddable
public class PartitionKey implements Key{
private String empname;
}
@Entity
public class Employee {
@EmbeddedId
private CompositePK id;
@Embedded
private PartitionKey name;
@Column(name="empid")
private int empid;
@Column(name="empname")
private String empname;
@Column(name="startdate")
private Date startdate;
@Column(name="enddate")
private Date enddate;
}
public class Loader{
private static EntityManager em;
public static void main(String [] args){
//code to instantiate em goes here
//...
//....
Query query = em.createNativeQuery("select empid,empname,startdate,enddate from employees", Employee.class );
List entities = query.getResultList();
//print the list
System.out.println(entities);
}
}
这样做的结果是填充了实体,但是其emidded字段的whereid和name为null。任何人都可以建议如何填充这两个字段?
由于