Reputation: 483
I'm going to develop an application which uses a RESTfull service and also I'm going to use JPA/Hibernate as the ORM. I have used these 2 technologies, but not in a single app.
Since client has no state, it is meaning less to use state full entities at the Data or Service Layer. And also there are bidirectional mappings as well.
I think CASCADE
option of JPA will not work, rather than it will destroy the data, if the client is making an update.
So what I'm thinking is, detach
objects before serve to the client and,
If there is an update (PUT
) request, just passing the parent object and update only the parent. So I cannot use CASCADE
option I suppose.
When it is a delete (DELETE
) request, I have to do the CASCADE
operations manually.
Also I think, making relationships between entities might be a problem.
Can anyone give a explanation about this scenario? Is this approach correct? Is there a best-practice on a situation like this?
Thanks!
Upvotes: 0
Views: 62
Reputation: 1428
Do not mix your business entities into the web layer.
I would recommend to decouple your business layer from the web layer creating new JAXB annotatted entities to return from your REST controller.
If you want to make easy your work, there are a lot of libraries that can copy 1 bean to another. For example the Apache BeanUtils.class.
Upvotes: 2