SAP / olingo-jpa-processor-v4

The JPA Processor fills the gap between Olingo V4 and the database, by providing a mapping between JPA metadata and OData metadata, generating queries and supporting the entity manipulations.
Apache License 2.0
123 stars 76 forks source link

Fields in @MappedSuperclass are not visible #105

Closed ejsthier closed 3 years ago

ejsthier commented 4 years ago

The fields from the base class are not visible when you you extend a base class with the @MappedSuperclass annotation.

Your entity doesn't have an id field in $metadata when your entity extends this class: `@MappedSuperclass abstract class AbstractEntity : Persistable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private var id: Int? = null`
wog48 commented 4 years ago

In in the $metadata document the sub type does not contains the field of the super type. The sub type only contains the extension. Please have a look at CSDL: 6 Entity Type

dm-ion commented 4 years ago

Looks to me like MappedSuperclass is not currently supported, only abstract parents which are annotated with Entity directly.

Looks like it would be pretty easy to add support for MappedSuperclass. You would need to:

  1. In IntermediateSchema.buildEntityTypeList you would have to use jpaMetamode.getManagedTypes (instead of .getEntities)

  2. Fix the knock on effects from that. Namely you would have to extend the JPAEdmNameBuilder to support the MappedSuperclassType in addition to using EntityType. So you'd need to figure out an appropriate name to use here as MappedSuperclassType doesn't have a .getName like EntityType does.

dm-ion commented 3 years ago

Hey @wog48 I think you can close this issue now as your latest enhancement seems to work great. 👍

dm-ion commented 3 years ago

@wog48 I was taking a look at this today, one thing I noticed with your implementation is that it only supports one mapped super class parent, JPA allows you to have multiple.

So if you were to have say:

AbstractEntity (@MappedSuperclass) | - AbstractTimeStampable (@MappedSuperclass) | -- Entity (@Entity)

You would not get fields from AbstractEntity.