@JoinTable JPA orderby列

时间:2018-07-26 10:36:40

标签: java jpa jointable

我正在尝试使用hibernate和jpa在sql下生成,但似乎无法正常工作。请帮助。

select
distinct sysservice0_.SERVICE_KEY as SERVICE1_88_, 
code1_.DISPLAY_NO as display_no 
from
SYS_MSS_SERVICE sysservice0_ 
left outer join
SYS_MSS_SERVICE_TMP sysservice0_1_ 
on sysservice0_.SERVICE_KEY=sysservice0_1_.SERVICE_KEY cross 
join
SYS_CODE code1_ 
where
sysservice0_.STATUS_FL=code1_.CODE_ID 
and code1_.STATUS_CD='A' 
and code1_.PARENT_FK='1'
order by
sysservice0_1_.SERVICE_KEY desc,
sysservice0_.SERVICE_STATUS desc,
sysservice0_.CHECKER_VERIFY_DT desc

我的休眠状态如下,但似乎不正确

Root<SysServiceCSS> serviceS = query.from( SysServiceCSS.class );
Root<Code> codeC = query.from( Code.class );  
List<Predicate> predicates = new ArrayList<Predicate>();  

//query.select(serviceS).distinct(true); 
query.select(serviceS);
predicates.add(builder.equal(serviceS.<String>get("statusFl"), codeC.<String>get("codeId") )); 
predicates.add(builder.equal(codeC.<String>get("statusCd"), "A" ));
predicates.add(builder.equal(codeC.<String>get("parentFk"), "1" ));  
query.orderBy(builder.asc(codeC.<String>get("displayNo")), builder.desc(serviceS.<String>get("serviceStatusTx")),builder.desc(serviceS.get("checkerVerifyDt")) );

实体类:

public class SysServiceCSS implements Serializable {

    @OneToOne 
    @JoinTable
    (
        name="SYS_MSS_SERVICE_TMP", 
        joinColumns={ @JoinColumn(name="SERVICE_KEY", referencedColumnName="SERVICE_KEY") },
        inverseJoinColumns={ @JoinColumn(name="SERVICE_KEY", referencedColumnName="SERVICE_KEY", unique=true) }
    ) 
    public SysServiceTempCSS sysServiceTempCSSM;

谢谢!

0 个答案:

没有答案