2 Replies Latest reply on Oct 21, 2012 11:09 AM by subaochen

    Question about EntityQuery and multiple tables

    lamikam

      Hello, I am a Seam and HQL/EJBQL newbie.  I need to add some constraints to an EntityQuery's restrictions, that joins with another table.  Here are the basics:

       


      public class UcbsvcoList extends EntityQuery<MyClass>

       

      private static final String EJBQL = "select ucbsvco from Ucbsvco ucbsvco";

       

      private static final String[] RESTRICTIONS = {
         "lower(ucbsvco.ucbsvcoSrceCode) like lower(#{ucbsvcoList.ucbsvco.ucbsvcoSrceCode})",
         "lower(ucbsvco.ucbsvcoSotpCode) like lower(#{ucbsvcoList.ucbsvco.ucbsvcoSotpCode})",
          ... more restrictions....

       

      Here is the query I need to execute:


      SELECT ucbsvco.*
        FROM ucbsvco, ucrevnt
      WHERE    <whatever restriction is used>
         AND  ucbsvco_code = ucrevnt_svco_code
                AND ucrevnt_nmac_ind = 'N'

       

      How do I override the SQL creation to add this?

       

      Thanks!

        • 1. Re: Question about EntityQuery and multiple tables
          lamikam

          Come on, people!  I need your wisdom.

          • 2. Re: Question about EntityQuery and multiple tables
            subaochen

            hi,

             

            Just to think about the reference of database table,that's the way that seam to deal with multiple tables.

             

            As to your situation, you should define some kind of reference to ucrevnt in Ucbsvco, for example:

             

            @Entity

            public class Ucbsvco implements Servialiable{

            ...

            private Set<Ucrevnt> evnts = new HashSet<Ucrevnt>(0);

            ...

             

            And in Ucrevnt:

             

            @Entity

            public class Ucrevnt implements Serialiable{

            ...

            private Ucbsvco ucbsvco;

            ...

            }

             

            Then in UcrevntList you can add such restriction like below:

             

            "ucrevnt.ucbsvco.code = #{#UcrevntList.ucrevnt.ucbsvco.code}",

             

            Hope to help you.