As far I know, it is impossible to call a stored procedure written in mysql with JPA
No. You can call stored procedures from JPA. See here for an example of how to do it.
How can I call a stored mysql function with usage of JPA?
You can call a MySQL stored function from JPA. JPA 2.1 introduces FUNCTION() function to call any pre-defined (such as CONCAT, SUBSTRING) or user-defined functions.
Say, for example, you've defined your own MySQL function such as shouldGetBonus
CREATE FUNCTION shouldGetBonus (INT department_id, INT project_id)
RETURNS boolean
DETERMINISTIC
BEGIN
DECLARE is_eligible boolean;
SET is_eligible = -- eligible to get bonus
RETURN is_eligible;
END$$
and then specify your function in your JPQL query, for example,
String query = "SELECT DISTINCT e FROM Employee e JOIN e.projects p WHERE FUNCTION('shouldGetBonus', e.department.id, p.id)"
TypedQuery<Employee> emps = entityManager.createQuery(query, Employee.class);
emps.getResultList();