需要JPA内部联接查询语法帮助

时间:2013-11-16 05:45:13

标签: java jpa openjpa

我想知道你们是否可以帮我解决我想写的OpenJPA查询 我有一个ItemEntity ......

@Entity(name = "item")
public class ItemEntity implements java.io.Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "itemid")
    @TableGenerator(name = "itemid", table = "items_sequence", allocationSize = 1)
    private Long id;
    @ManyToOne
    private ImportPayloadEntity importPayloadEntity;

还有一个ImportPayloadEntity ......

@Entity(name = "import_payload")
public class ImportPayloadEntity implements java.io.Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.TABLE, generator = "importpayloadid")
    @TableGenerator(name = "importpayloadid", table = "import_payload_sequence", allocationSize = 1)
    private Long id;
    @Column(name = "PROCESSED_IND")
    private String processedInd;

我正在尝试从我的项目实体中选择加入我的导入有效负载实体,以确保processedInd等于'N'。

我无法获得正确的语法。我尝试了一些东西,但这是我最近的尝试..

@NamedQuery(name = "queryItems", query = "SELECT c1, c2 FROM item c1 INNER JOIN c1.importPayloadEntity c2 WHERE c2.processedInd='N'")

这给了我......

Unknown column 't0.IMPORTPAYLOADENTITY_ID' in 'on clause' {prepstmnt 1719904819 SELECT t0.id, t1.id, t1.FILENAME, t1.LOAD_DATETIME, t1.IMPORT_PAYLOAD_BODY, t1.IMPORT_PAYLOAD_TYPE, t1.PROCESSED_DATETIME, t1.PROCESSED_IND FROM item t0 INNER JOIN import_payload t1 ON t0.IMPORTPAYLOADENTITY_ID = t1.id WHERE (t1.PROCESSED_IND = ?)} [code=1054, state=42S22]

感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您可以尝试select i from Item i where i.importPayloadEntity.processedInd = 'N'