Jpa 将本机查询映射到JPQL(使用额外的连接条件>;>;ON…和…)

Jpa 将本机查询映射到JPQL(使用额外的连接条件>;>;ON…和…),jpa,jpql,Jpa,Jpql,JPA实体 组织实体 @Entity public class Organization implements Serializable{ private Integer id; // @Id private String name; // Getters and Setters } @Entity public class Place implements Serializable{ private Integer id; // @Id privat

JPA实体

组织实体

@Entity
public class Organization implements Serializable{
    private Integer id; // @Id
    private String name;

    // Getters and Setters
}
@Entity
public class Place implements Serializable{
    private Integer id; // @Id
    private String name;
    private Organization organization; // @ManyToOne relation

    // Getters and Setters
}
@Entity
public class Profile implements Serializable{
    private String username;// @Id
    private Set<VisitedPlace> visitedPlaces; // @OneToMany(mappedBy = "profile")
    // Getters and Setters
}
@Entity
public class VisitedPlace implements Serializable{
    private Integer id; // @Id
    private Date visitedDate;
    private Place place; // @ManyToOne relation
    private Profile profile; // @ManyToOne relation

    // Getters and Setters
}
放置实体

@Entity
public class Organization implements Serializable{
    private Integer id; // @Id
    private String name;

    // Getters and Setters
}
@Entity
public class Place implements Serializable{
    private Integer id; // @Id
    private String name;
    private Organization organization; // @ManyToOne relation

    // Getters and Setters
}
@Entity
public class Profile implements Serializable{
    private String username;// @Id
    private Set<VisitedPlace> visitedPlaces; // @OneToMany(mappedBy = "profile")
    // Getters and Setters
}
@Entity
public class VisitedPlace implements Serializable{
    private Integer id; // @Id
    private Date visitedDate;
    private Place place; // @ManyToOne relation
    private Profile profile; // @ManyToOne relation

    // Getters and Setters
}
配置文件实体

@Entity
public class Organization implements Serializable{
    private Integer id; // @Id
    private String name;

    // Getters and Setters
}
@Entity
public class Place implements Serializable{
    private Integer id; // @Id
    private String name;
    private Organization organization; // @ManyToOne relation

    // Getters and Setters
}
@Entity
public class Profile implements Serializable{
    private String username;// @Id
    private Set<VisitedPlace> visitedPlaces; // @OneToMany(mappedBy = "profile")
    // Getters and Setters
}
@Entity
public class VisitedPlace implements Serializable{
    private Integer id; // @Id
    private Date visitedDate;
    private Place place; // @ManyToOne relation
    private Profile profile; // @ManyToOne relation

    // Getters and Setters
}
这将创建这些表,但我也将用示例数据显示它

组织机构表

 ===================== 
| id |      name      |
-----+----------------+
| 1  | Organization 1 |
 =====================
 ================================= 
| id |   name   | organization_id |
-----+----------+-----------------+
| 1  | Place 1  |        1        |
-----+----------+-----------------+
| 2  | Place 2  |        1        |
-----+----------+-----------------+
| 3  | Place 3  |        1        |
 =================================
 ============= 
|  username   |
--------------
| 111@xxx.com |
--------------
| 222@xxx.com |
 =============
 ================================================ 
| id | visiteddate | place_id | profile_username |
-----+-------------+----------+---------------- -+
| 1  | 2017-01-01  |     1    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 2  | 2017-02-01  |     2    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 3  | 2017-01-15  |     1    |   111@xxx.com    |
 ================================================
放置表格

 ===================== 
| id |      name      |
-----+----------------+
| 1  | Organization 1 |
 =====================
 ================================= 
| id |   name   | organization_id |
-----+----------+-----------------+
| 1  | Place 1  |        1        |
-----+----------+-----------------+
| 2  | Place 2  |        1        |
-----+----------+-----------------+
| 3  | Place 3  |        1        |
 =================================
 ============= 
|  username   |
--------------
| 111@xxx.com |
--------------
| 222@xxx.com |
 =============
 ================================================ 
| id | visiteddate | place_id | profile_username |
-----+-------------+----------+---------------- -+
| 1  | 2017-01-01  |     1    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 2  | 2017-02-01  |     2    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 3  | 2017-01-15  |     1    |   111@xxx.com    |
 ================================================
配置文件表

 ===================== 
| id |      name      |
-----+----------------+
| 1  | Organization 1 |
 =====================
 ================================= 
| id |   name   | organization_id |
-----+----------+-----------------+
| 1  | Place 1  |        1        |
-----+----------+-----------------+
| 2  | Place 2  |        1        |
-----+----------+-----------------+
| 3  | Place 3  |        1        |
 =================================
 ============= 
|  username   |
--------------
| 111@xxx.com |
--------------
| 222@xxx.com |
 =============
 ================================================ 
| id | visiteddate | place_id | profile_username |
-----+-------------+----------+---------------- -+
| 1  | 2017-01-01  |     1    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 2  | 2017-02-01  |     2    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 3  | 2017-01-15  |     1    |   111@xxx.com    |
 ================================================
访问地点表

 ===================== 
| id |      name      |
-----+----------------+
| 1  | Organization 1 |
 =====================
 ================================= 
| id |   name   | organization_id |
-----+----------+-----------------+
| 1  | Place 1  |        1        |
-----+----------+-----------------+
| 2  | Place 2  |        1        |
-----+----------+-----------------+
| 3  | Place 3  |        1        |
 =================================
 ============= 
|  username   |
--------------
| 111@xxx.com |
--------------
| 222@xxx.com |
 =============
 ================================================ 
| id | visiteddate | place_id | profile_username |
-----+-------------+----------+---------------- -+
| 1  | 2017-01-01  |     1    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 2  | 2017-02-01  |     2    |   111@xxx.com    |
-----+-------------+----------+------------------+
| 3  | 2017-01-15  |     1    |   111@xxx.com    |
 ================================================
我的问题是如何将下一个本机SQL查询映射到JPQL

所以我会得到下一个结果

 ===================== 
|  username   | count |
 -------------+-------
| 111@xxx.com |   2   |
 -------------+-------
| 222@xxx.com |   0   |
 =====================
我一直在尝试下一个JPQL

但它确实回来了

 ===================== 
|  username   | count |
 -------------+-------
| 111@xxx.com |   2   |
 =====================
所以我真正的问题是将下一行转换为JPQL

左连接位置打开vp.place\u id=pl.idpl.organization\u id=1


不幸的是,只有JPA2.1规范才支持在子句上添加

因此,到目前为止,我们还不能在
子句上使用with

您可以从以下站点获得JPA2.1规范:


所以希望我们能在下一个版本中得到它。

不幸的是,只有JPA2.1规范才支持在
上添加

因此,到目前为止,我们还不能在
子句上使用with

您可以从以下站点获得JPA2.1规范:

所以希望我们能在下一个版本中得到它