简体   繁体   English

未实现Olingo OData V2读取属性

[英]Olingo OData V2 Read Property not implemented

I implemented an OData V2 Service with Apache Olingo V2 in connectin with JPA using EclipseLink. 我使用EclipseLink在与JPA的connectin中使用Apache Olingo V2实现了OData V2服务。 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: 所有请求都工作正常,但是到了这一点,我想通过来自实体集的GET请求(如以下URL)访问单个属性:

http://localhost:8080/MyODataService/XXXXXX.svc/EntitySet(12345)/Property 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: 扩展ODataJPASeviceFactory的类如下所示:

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? 现在我的问题是:如何实现功能,以便不仅可以对整个实体集执行GET和POST请求,而且还可以针对实体集的单个属性(如我尝试使用上述URL一样)进行GET和POST请求?

Accessing a single property from one entity is currently not implemented if you use the Olingo JPA Extension. 如果您使用Olingo JPA扩展,则当前无法实现从一个实体访问单个属性。

If you want to support this behaviour you can register a custom processor and only override the "readEntityComplexProperty" and "readEntitySimpleProperty" methods. 如果要支持此行为,则可以注册自定义处理器,并且仅覆盖“ readEntityComplexProperty”和“ readEntitySimpleProperty”方法。 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. 您不重写的每个方法都将导致执行标准Olingo功能。

Here is a tutorial on how to register a custom JPA processor: http://olingo.apache.org/doc/odata2/tutorials/CustomODataJPAProcessor.html 这是有关如何注册自定义JPA处理器的教程: 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 这是关于如果您自己实现功能的代码的示例: 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. 例如,要访问以下URL: http:// localhost:8080 / myService.svc / Cars ('6')/ Manufacturer,您需要在汽车与制造商关联集之间创建关联。 Have a look at the documentation: https://olingo.apache.org/doc/odata2/tutorials/basicread.html 看看文档: https : //olingo.apache.org/doc/odata2/tutorials/basicread.html

Hegg, 黑格

you can use 您可以使用

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

Bye 再见

Domenico 多梅尼科

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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