0

I am using grails 2.1.1. Here I have 2 domain. One is -InvIssue- and other is -SlsDoMst-. There is a foreign key of SlsDoMst in InvIssue domain. Now I need to find all the SlsDoMst row that is not in InvIssue table. So far I am using plain sql for now as follows ::

my oracle query >>>

    SELECT MS. *
FROM SLS_DO_MST MS
LEFT OUTER JOIN INV_ISSUE ISS ON MS.MID = ISS.SLS_DO_MST_MID

But I need to do this with criteria query. My domain are as follows ::

InvIssue >>>

    class InvIssue{
    String clnCode
    Long id
    SlsDoMst slsDoMst
    String remk
}

SlsDoMst >>>

    class SlsDoMst {
    Long id
    String code
}
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82

2 Answers2

0

I have done it with hql and gorm query as follows. Hope it will be usefull >>>

def ids = inv.InvIssue.executeQuery("select iss.slsDoMst.id From inv.InvIssue iss where iss.slsDoMst.id is not null")
    def list = SlsDoMst.findAll()
    if(ids.size() > 0){
        list = SlsDoMst.findAllByIdNotInList(ids)
    }
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82
0

This might work:

import static org.hibernate.sql.JoinType.*

def list = InvIssue.withCriteria {
    createAlias 'slsDoMst', 'mst', RIGHT_OUTER_JOIN

    projections {
        property 'mst'
    }

    isNull 'id'
}

I'm just not sure if the projection will work. If not, you can use this HQL:

select b from InvIssue as a right outer join a.slsDoMst as b where a.id is null
Emmanuel Rosa
  • 9,697
  • 2
  • 14
  • 20
  • this message is shown :: `join type not supported by OracleJoinFragment (use Oracle9iDialect/Oracle10gDialect)` – Sumon Bappi Jan 17 '16 at 06:48