JPA使用createNativeQuery映射嵌入字段

JPA使用createNativeQuery映射嵌入字段,jpa,mapping,Jpa,Mapping,我有一个实体,它有一个字段表示用embeddeid注释的复合主键,另一个字段用embedded注释。 这两个字段都不会直接映射到传递给createNativeQuery方法的查询返回的列。 getResultList返回实体列表,但我提到的两个字段在所有实体中都为空 public interface Key{ public int hashCode() } @Embeddable public class CompositePK impements Key{ private int e

我有一个实体,它有一个字段表示用embeddeid注释的复合主键,另一个字段用embedded注释。 这两个字段都不会直接映射到传递给createNativeQuery方法的查询返回的列。 getResultList返回实体列表,但我提到的两个字段在所有实体中都为空

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);
 }
}
其结果是填充了实体,但其字段SID和名称(作为emded字段)为空。有人能建议如何填充这两个字段吗


谢谢

为什么要将此标记为“嵌入式”?可能不太合适。我是JPA新手。所以我不确定我是否正确,但我想保留实体来保存对象,而不是对另一个对象的引用。“嵌入式”标签用于嵌入式计算——微控制器等