Hi people,
I want to throw this question that is not very clear for me, and I need some opinions on the subject.
The topic is as follows:
Im working with Hibernate 3 and i have in my domain model classes (User Event, Country, State, City)... With their respective relationships.
The doubt comes because I am doing a CRUD of these entities and when i have to delete a country, i have to validate that the country is not subject to any other object associated...eg Event, User , and so on.
Now I have to do this two approaches ...
1 - Get each of the objects that contain the entity to eliminate (Country), and check that there is no association ...
Code:
if (!Evento.getPais (). Equals (paisAEliminar)) { ....
... validation message.
}
and so with each of my objects in the domain model Country have ...
which is a long and tedious process ... and the performante is poor...
Or, ...
2 - Directly delete the country and leave the BD check for violation of the constraints. (In this case the issue is complicated to know who was really what happened ... because the BD launch a ¿XXXJDBCException? ...
That will be cached by Hibernate wrapper and later to one of its exceptions...
My Point is ...
Which of the two approaches used, preferred and / or I advise you ...
Is there any other way to perform these validations business ...??
many thanks to all ...
Mauro.