忽略 Apache Olingo 中的字段
Ignoring Field in Apache Olingo
目前我的项目正在使用 JPA 进行数据库连接。
我也在使用默认的 OdataJPA 处理器。
如何实现 not 在我的 odata2 API 响应中包含某些字段,例如 ("password")。还是我真的必须实施 customOdataJPAProcessor?
排除某些 JPA 实体属性的最简单方法是定义 JPA-EDM 映射模型。这基本上是一个遵循 this schema. You can read more about it in the documentation here: redefining OData JPA metadata.
的 XML 文件
您有两种不同的链接映射模型的方法 XML,或者指定位于 WEB-INF 文件夹中的文件的文件名(假设您正在构建 WAR)或者,如果这不够灵活,您可以创建一个 JPA EDM extension and return the mapping model file as a stream.
这样的文件可能是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<JPAEDMMappingModel xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<PersistenceUnit name="My_Persistence_Unit">
<JPAEntityTypes>
<JPAEntityType name="MyEntity">
<EDMEntityType>MyEntity</EDMEntityType>
<EDMEntitySet>MyEntities</EDMEntitySet>
<JPAAttributes>
<JPAAttribute name="attribute" exclude="true" />
</JPAAttributes>
<JPARelationships />
</JPAEntityType>
</JPAEntityTypes>
<JPAEmbeddableTypes />
</PersistenceUnit>
</JPAEDMMappingModel>
目前我的项目正在使用 JPA 进行数据库连接。
我也在使用默认的 OdataJPA 处理器。
如何实现 not 在我的 odata2 API 响应中包含某些字段,例如 ("password")。还是我真的必须实施 customOdataJPAProcessor?
排除某些 JPA 实体属性的最简单方法是定义 JPA-EDM 映射模型。这基本上是一个遵循 this schema. You can read more about it in the documentation here: redefining OData JPA metadata.
的 XML 文件您有两种不同的链接映射模型的方法 XML,或者指定位于 WEB-INF 文件夹中的文件的文件名(假设您正在构建 WAR)或者,如果这不够灵活,您可以创建一个 JPA EDM extension and return the mapping model file as a stream.
这样的文件可能是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<JPAEDMMappingModel xmlns="http://www.apache.org/olingo/odata2/jpa/processor/api/model/mapping">
<PersistenceUnit name="My_Persistence_Unit">
<JPAEntityTypes>
<JPAEntityType name="MyEntity">
<EDMEntityType>MyEntity</EDMEntityType>
<EDMEntitySet>MyEntities</EDMEntitySet>
<JPAAttributes>
<JPAAttribute name="attribute" exclude="true" />
</JPAAttributes>
<JPARelationships />
</JPAEntityType>
</JPAEntityTypes>
<JPAEmbeddableTypes />
</PersistenceUnit>
</JPAEDMMappingModel>