简体   繁体   中英

Olingo OData V2 Read Property not implemented

I implemented an OData V2 Service with Apache Olingo V2 in connectin with JPA using EclipseLink. All requests are working fine, but when it comes to the point, where I want to access a single property via GET request from an entity set like for the following URL:

http://localhost:8080/MyODataService/XXXXXX.svc/EntitySet(12345)/Property

the response in return is:

<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
           <message xml:lang="de-DE">Not implemented</message>
</error>

The class which extends the ODataJPASeviceFactory looks as follows:

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.apache.olingo.odata2.jpa.processor.api.ODataJPAContext;
import org.apache.olingo.odata2.jpa.processor.api.ODataJPAServiceFactory;
import org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException;


public class JPAODataServiceFactory extends ODataJPAServiceFactory
{

    private static final String PERSISTENCE_UNIT_NAME = "MyPersistenceUnitName";

    @Override
    public ODataJPAContext initializeODataJPAContext() throws ODataJPARuntimeException
    {

        ODataJPAContext oDatJPAContext = this.getODataJPAContext();
        try
        {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
            oDatJPAContext.setEntityManagerFactory(emf);
            oDatJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);

            return oDatJPAContext;

        } catch (Exception e)
        {

            throw new RuntimeException(e);

        }

    }

My question now is: How do I implement the functionality, so that I can do GET and POST requests not only for a whole entity set, but also for a single property of an entity set like I tried with the mentioned URL?

Accessing a single property from one entity is currently not implemented if you use the Olingo JPA Extension.

If you want to support this behaviour you can register a custom processor and only override the "readEntityComplexProperty" and "readEntitySimpleProperty" methods. There you can have your custom code where you specifically get back the value. Every method you don`t override will result in the standard Olingo functionality being executed.

Here is a tutorial on how to register a custom JPA processor: http://olingo.apache.org/doc/odata2/tutorials/CustomODataJPAProcessor.html

Here is the example on how your code can look like if you implement the functionality yourself: https://github.com/apache/olingo-odata2/blob/597465569fdd15976d0486711d4a38f93a7c6696/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java#L592

You need to create an association between your entity sets. For example, to access the following URL: http://localhost:8080/myService.svc/Cars ('6')/Manufacturer, you need to create an assocation between your car and your manufacturer association sets. Have a look at the documentation: https://olingo.apache.org/doc/odata2/tutorials/basicread.html

Hegg,

you can use

http://localhost:8080/MyODataService/XXXXXX.svc/EntitySet(12345)/ ?$select=Property

Bye

Domenico

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM