如何编写,用spring数据jpa选择子句子查询?

时间:2017-07-03 03:03:23

标签: java mysql spring-boot spring-data-jpa jpql

我有什么
 我正在做春季启动项目  2.以下是两个域

a)

@Entity
@Table(name="oc_country")  
public class Country {  
    @Id  
    @GeneratedValue(strategy=GenerationType.AUTO)  
    @Column(name="country_id", nullable=false, length=11)  
    private int countryId;  
    @Column(name="name",nullable=false,length=128)  
    private String name;  
    @Column(name="iso_code",nullable=false,length=2)  
    private String isoCode;  
    @Column(name="phonecode",nullable=false,columnDefinition="int(5)")  
    private int phoneCode;          
}

b)中

@Entity  
public class ExchangeCountry{  
    @Id    
    @GeneratedValue(strategy=GenerationType.AUTO)    
    private Long id;    
    @Column(name="country_id", nullable=false, length=11)    
    private int countryId;    
    private String fiatCurrency;    
    private boolean isDeleted=false;    
    @Column()     
    @Temporal(TemporalType.TIMESTAMP)    
    private Date createdDate = new Date();    
    @Column()     
    @Temporal(TemporalType.TIMESTAMP)  
    private Date updatedDate = new Date();  
    private Boolean isGlobalExchange=false;  

}  
  1. 使用mysql作为数据库
  2. 当我写下mysql查询时,我得到了结果 查询: - > select ex.country_id, (select name from oc_country c where c.country_id=ex.country_id) as countryName from exchange_country ex;
  3. 我想要什么
     1.如何在两个实体中用JpaRepository(spring data jpa)编写select子句子查询?
     2.有没有办法从jpa(spring data jpa)或其他概念写上面的mysql查询?

    由于

0 个答案:

没有答案