There are scenarios when dealing with service layer in liferay, when we need to query database with too many clauses or dealing with multiple tables.In such cases,we use either of:
1)Dynamic query(wrapper on Hibernate criteria API)
2)Custom SQL queries
References: