0

我正在使用 Play 框架 1.2.4

我创建了 3 个具有关系的模型类:

标题 <1 - n> 行 - 1> LineType

@Entity
public class Header extends Model {
   @OneToMany(mappedBy="header" , cascade=CascadeType.ALL)
   public List<Line> lines;
   ...
}

@Entity
public class Line extends Model{
   @ManyToOne
   public Header header ;

  @ManyToOne
   publicLineType lineType;
   ...
}

@Entity
public class LineType extends Model {

   public Integer code ;
   ...
}

我想在标题搜索期间对线型进行过滤。

如何在 Play Framework 中使用 JPQL(或其他)编写此 SQL 查询的等效项?

 Select * from header where exists(select 1 from line,typeline where line.header=header.id and  line.lineType=linetype.id and linetype.code = 'X')
4

1 回答 1

1

我回答我自己的问题:

Query query = JPA.em().createQuery("select header from Header as header where exists(select line from Line line JOIN ligne.lineType as type where ligne.header=header and type.code='X')");
List<Header> headers = query.getResultList();

内连接:http ://docs.oracle.com/html/E24396_01/ejb3_langref.html#ejb3_langref_inner_joins

存在:http ://docs.oracle.com/html/E24396_01/ejb3_langref.html#ejb3_langref_exists

于 2012-07-06T10:00:01.123 回答