Reputation: 5849
I am developing JSF project which connect to mySql Database and I have for example two ways to delete element like
// deletePerson()
People p = selectedPerson;
1- direct access to the database using entity manager
ut.begin();
p = em.merge(p);
em.remove(p);
ut.commit();
2- using restful web service to access the data
PeopleClient client = new PeopleClient();
client.remove(p.getId().toString());
which is the better way to do that with reasons?
Upvotes: 0
Views: 74
Reputation: 7275
I would say it depends on the bigger picture for your data.
If you want to some day build more applications around your data (mobile application, web application, client side application), then I would go with the RESTful web service. You can more easily leverage that in other codebases.
If you just need the data for this one application, then I would go with the direct database approach.
The big thing to keep in mind is how many network hops you have. The REST service is going to have to access the database directly. REST = two network trips (one from application to REST service, one from REST service to database). Database = one network trip.
Upvotes: 1