我使用 EclipseLink 与 JPA 连接,使用 Apache Olingo V2 实现了 OData V2 服务。所有请求都工作正常,但说到这一点,我想通过来自实体集的 GET 请求访问单个属性,例如以下 URL:
http://localhost:8080/MyODataService/XXXXXX.svc/EntitySet(12345)/Property
作为回报的回应是:
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<code/>
<message xml:lang="de-DE">Not implemented</message>
</error>
扩展 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);
}
}
我现在的问题是:如何实现该功能,以便我不仅可以对整个实体集执行 GET 和 POST 请求,还可以对实体集的单个属性执行 GET 和 POST 请求,就像我尝试使用提到的 URL 一样?