The problem is that i do not know which exception to catch when the find(...) method does not find the entity for the totoId parameter.
I think there is some confusion about what Spring does in this case. When a Hibernate(or whatever provider you are using ) Exception or an SQLException gets thrown, Spring will translate the exception to a runtime exception within the DataAccessException hierarchy. entityManager.find() does not throw an exception if the entity is not found it returns null. As a matter of fact the only exception that em.find should throw is an IllegalArgumentException if the first argument does not denote an entity type or the second argument is is not a valid type for that entity’s primary key or is null.
If an exception is occurring and is being swallowed somehow, I would catch generic Exception e in your methodFoo() and log the stack trace. Then
you should be able to determine the problem based on that. The ClassCastException you are referencing says you are trying to cast a
String to a Toto object which of course is illegal. I have not looked closely at all the code you posted, mainly because it is a more productive use of my time to have the full stack trace first.
Good Luck