Search code examples
javahibernatelaravelhql

How can create HQL Query like Laravel?


My laravel eloquent is the following:

Module::select(['a', 'b'])
                ->whereRaw("OR a ='one' OR a = 'five' OR a ='ten'")
                ->distinct()
                ->orderBy('a', 'ASC')
                ->get();

How can I convert it into hibernate?


Solution

  • You can use the toSql() method to get the SQL query.

    For example

    DB::table('users')->toSql(); 
    

    returns the query

    select * from users
    

    Then you have to translate the SQL to HQL, using some manual.