I would like to understand the difference between a static query and a dynamic query. Which one would be the ideal one to use in an applications and what are the advantage in using a specific querying type.
Dynamic queries are re-usable and static queries need to be defined each use.
dynamic queries are constructed "on the fly" at run time thus the same code can produce different queries each time it is executed. The query is compiled when you prepare the query. Access rights to the data are determined when the query is prepared.
static quereis are constructed at compile time (though you can include variables in the expressions in the query's static where clause).