views:

86

answers:

4
+2  Q: 

REST and JAVA JPA

I am trying to understand the code of some project which is not properly documented.Am the only developer working on the task.I dont have much experience. There is a data model and there are some classes witten to access it.It was mentioned that the data model has some rest api on top of it.But when i see the code i can see getter code which makes some rest call to some uri. But i look at setter methods it has plain jpa used to persisit the object. ex extitymanger.persist(objname).

Now is it possible to use REST interface for getting the data and using JPA to persiste the data?

A: 

That's definitely possible. It sounds like the access classes are abstracting around a database for storage. Thus it's behaving like a DAO and using JPA to access the datasource. For the getters your access class is using an exposed REST interface from some service. So rather than using JPA to query and return the data, it's using a service that's performing the same tasks.

Maybe the REST interface is a get only and doesn't provide a mechanism for storing data and that's why the direct JPA is used.

John Engelman
thanks for replying john.Can u plz tell me why they could have done like that?Why not directy use JPA to get the data too?
akp
There could be a variety of reasons, but I would guess that maybe the query code is complex and already existed as part of a service and they didn't want to replicate it. The REST interface is probably being backed by the same database that's being accessed by the JPA code. Is there a particular concern here? From your code's perspective you are using the accessor class that already exists so it shouldn't matter how they've implemented the get/set methods.
John Engelman
thanks john.Do u have any more inputs on this? It would be great help for me
akp
+1  A: 

Yes, it is possible. Without knowing more it is not possible to know if it is effective. My instincts tell me it is not the best solution.

Jacob Tomaw
thanks jacob.Why they must have done like that?
akp
Very often unscrupulous engineers will test out new technologies only to change to something else at the mid-point. This can result in a jumbled mess for others to support. It is also possible that they were in the middle of refactoring when requirements or business value changed.
Jacob Tomaw
+3  A: 

It is possible to use JPA for all the rest operations. You can check out an example I posted to my blog:

Blaise Doughan
A: 

I think the best thing to do is to forget trying to work out the individual pieces of code and focus on the big picture. Work out all of the inputs and all of the outputs. Even write some test cases to test various inputs create various outputs.

That way you can understand what the code does without needing to know all of the minor ddetails.

corydoras