我正在使用Toplink Essentials(JPA)+ GlassFish v3 + NetBean 6.9

我有一个带有复合主键的表:

table (machine)
----------------
|PK machineId  |
|PK workId     |
|              |
|______________|

我创建了2个实体类,一个是实体本身,第二个是PK类。
public class Machine {
   @EmbeddedId
   protected MachinePK machinePK;

   //getter setters of fields..
}

public class MachinePK {
    @Column(name = "machineId")
    private String machineId;

    @Column(name = "workId")
    private String workId;

}

现在.. 如何在带有WHERE的JPQL中编写SELECT子句?

这失败了。
SELECT m FROM Machine m WHERE m.machineId = 10

http://www.mail-archive.com/[email protected]/msg03073.html

根据网页,添加“val”?不,它也失败。
   SELECT m FROM Machine m WHERE m.machineId.val = 10

在这两种情况下,错误均为:
    Exception Description: Error compiling the query
[SELECT m FROM Machine m WHERE m.machineId.val = 10],
line 1, column 30: unknown state or association field
[MachineId] of class [entity.Machine].

最佳答案

SELECT m FROM Machine m WHERE m.machinePK.machineId = 10

10-06 15:24