2016-08-19 108 views
0

以下是我想要轉換爲HQL的SQL。有人可以幫助我嗎?我也張貼我的HQL這是目前給我一個空指針異常 -多重內部加入HQL

select ti.tax_id_no, 
    u1.user_id, 
    u1.user_nm_fst, 
    u1.user_nm_lst, 
    u1.user_ph_no, 
    u1.user_email 
    from pcmp.tax_identifier ti 
    inner join (select ucax.user_id, ucax.cust_id 
      from pcmp.users_customer_access_xref ucax 
      where ucax.ptcp_typ_cd = 'insrd' 
      and ucax.void_ind = 'n' 
      and ucax.user_cust_accs_xref_end_dt is null) ucax1 
on ucax1.cust_id = ti.cust_id 
inner join (select u.user_id, 
       u.user_nm_fst, 
       u.user_nm_lst, 
       u.user_ph_no, 
       u.user_email 
      from pcmp.users u 
      where u.user_end_dt is null 
      and u.user_void_ind = 'n') u1 
on u1.user_id = ucax1.user_id 
where ti.tax_id_no = '830204947'-- '465202523' 
and ti.void_ind = 'n' 
and ti.tax_id_end_dt is null 

我嘗試使用下面的查詢,但遇到了錯誤 -

 String queryString = "select u from User u" 
       + " INNER JOIN u.ucax userCustomerAccessXref"     
       + " INNER JOIN u.ti taxIdentifier" 
       + " where taxIdentifier.tax_id_id = ?1"; 

的例外,我得到使用上述查詢 -

顯示java.lang.NullPointerException

org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:383) 
org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:3585) 
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3366) 
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3239) 
org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:726) 

回答

0

讓我們知道VERSI你正在運行的休眠模式。 這可能有助於將您的問題儘可能地重現爲其他人。 對於任何不在您業務領域的人來說,您的內心似乎都非常複雜......

每當您通過串聯字符串開始查詢...對我而言,這表示您失去了對您的業務領域的控制權,不要選擇指定jpa/hibernate查詢外化的方式。