Is there a way to implement an ORM repository with a Rest service as datasource?

0

I wanted to make several applications / modules that communicate through webservices Rest, I like to use the dao pattern and I was looking for if jpa or hibernate or spring data (in general an ORM), they allowed to do this kind of thing, that is, consult a jpa repository but instead of consulting a database, consult a webservice. I know that it is only to create the queries to the service in rest, but I remain with the professional doubt of if it is possible to use an ORM or some other implementation that allows to consult one on a rest resource.

It suddenly occurred to me to expose a service with ODATA, graphql and call it a repository but I did not find something to read from a repository of an orm or something similar.

Is there a way to do this in this way? Is there another way to implement what I want? Is it wrong to want to do this from the point of good practice? Can the modules be communicated in another way?

    
asked by phipex 01.07.2017 в 02:09
source

1 answer

1

I do not know if I understand the question well. Anything warns me. By starting an ORM framework it is used to map relational entities from a database to objects with which you can interact. Obviously they have more things that manage the operation of the persistence layer of an application. On the other hand, the idea of a REST service is to take advantage of the HTTP protocol in order to interact with, for example, an application. There are several things in your question, maybe what you need is simply to communicate different apps through http calls.

To do this you can make an application respond to different requests by serializing some object eg in the form of JSON. Another application that consumes it must make the call to the first one and be able to interpret its message.

You can use many things for each problem segment. For example, it could be an application with Spring that solves requests in JSON form and another that can consume it (to make the calls there are libraries, both native and not, eg, apache or resttemplate) and interpret directly with spring an object or using GSON or JAXB. The possibilities are endless.

There are several tutorials like link or link

There are other forms of communication and perhaps they come close to what you need like RMI applications where you can use objects that "live" in other applications, but they are solutions that are somewhat obsolete and clearly not REST.

What you should keep in mind is that each solution is designed for a specific problem. The connection / communication, serialization, are independent of persistence problems.

In summary, when you want to save an object, for example, you will have to transfer it to another application and save it if you want to save it in the way that best suits you.

    
answered by 04.07.2017 в 20:59