这个SQL查询如何转换为JPQL?

时间:2011-02-28 14:09:57

标签: mysql sql jpql

我试图习惯于JPQL,但我已经卡住了。这是怎么回事:

SELECT * FROM Table_a INNER JOIN Table_b USING (Table_bID) Where Table_b.Column_a LIKE 'somestring'

翻译为JPQL?我非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

select a from EntityMappedToTableA 
inner join fetch a.entityMappedToTableB b
where b.fieldMappedOnColumnA like :someString

为了实现这一点,你必须有一个关系(我假设它是一个ManyToOne,因为表A中似乎有几行具有表B的ID),从EntityMappedToTableA到EntityMappedToTableB:

@Entity
public class EntityMappedToTableA {
    @ManyToOne
    @JoinColumn(name = "Table_bID")
    private EntityMappedToTableB entityMappedToTableB;

    // ...
}