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
122 stars 76 forks source link

Subtype of complex type is it supported? #187

Closed rahul3197 closed 1 year ago

rahul3197 commented 1 year ago

I tried subtype of complex type, but i am getting this error while fetching entity. OData Library: An exception without message text was thrown.

Also i read, eclipselink does not support inheritence of Embeddable. If it is supported, please give me a reference on how to implement it.

wog48 commented 1 year ago

Hello,

I tried the following:

@Embeddable
public class Location {

  @Column(name = "\"Address\"")
  private String address;
}
@Embeddable
public class AirportLocation extends Location {

  @Column(name = "\"Longitude\"")
  private BigDecimal longitude;
}

And got the following metadata:

<ComplexType Name="Location">
    <Property Name="Address" Type="Edm.String" MaxLength="255"/>
</ComplexType>
<ComplexType Name="AirportLocation" BaseType="Trippin.Location">
   <Property Name="Longitude" Type="Edm.Decimal"/>
</ComplexType>

To analyse your problem I need more details about your model. Can you provide more insides into your model? You can also try to get more insides by debugging. Set a breakpoint in org.apache.olingo.server.core.ODataHandlerImpl at line 89: processInternal(request, response); Jump over and look at the exception thrown.

rahul3197 commented 1 year ago

Hi, metadata endpoint is working for me also, but while fetching data, it is throwing error .

i have a complex type called Location

@Embeddable 
@Data
 public class Location {

    @Column(name = "Address")
    private String address;

    @Column(name = "City")
    @AttributeOverrides(value =  {@AttributeOverride(name = "name", column = @Column(name = "LocationCityName")), @AttributeOverride(name = "countryRegion", column = @Column(name = "LocationCityCountryRegion")), @AttributeOverride(name = "region", column = @Column(name = "LocationCityRegion"))})
    @Embedded
    private City city;

    @Column(name = "Code")
    private Integer code;
  }

i have a complex type eventLocation extending Location

@Embeddable
@Data
public class EventLocation extends Location {
    public EventLocation() {
        super();
    }

    @Column(name = "BuildingInfo")
    private String buildingInfo;
}

Now i have a entity which has eventLocation as complex type

@Entity(name = "Event")
@Table(name = "Event", schema = "Trippin")
@Data
public class Event {
    @EdmIgnore
    @Id
    @Column(name = "EventId")
    private Integer eventId;
    @Column(name = "Description")
    private String description;
    @Column(name = "OccursAt")
    @Embedded
    //@AttributeOverrides(value = {@AttributeOverride(name = "address", column = @Column(name = "EventLocationAddress")), @AttributeOverride(name = "code", column = @Column(name = "EventLocationCode")), @AttributeOverride(name = "buildingInfo", column = @Column(name = "EventBuildingInfo"))})
    private EventLocation eventLocation;
}

when i am hitting Events entity set http://localhost:9010/Trippin/v1/Events i am getting this error :

{
    "error": {
        "code": null,
        "message": "OData Library: An exception without message text was thrown."
    }
}

metadata endpoint is working fine.

 <ComplexType Name="Location">
                <Property Name="Code" Type="Edm.Int32"/>
                <Property Name="Address" Type="Edm.String" MaxLength="255"/>
                <Property Name="City" Type="Trippin.City"/>
            </ComplexType>
  <ComplexType Name="EventLocation" BaseType="Trippin.Location">
      <Property Name="BuildingInfo" Type="Edm.String" MaxLength="255"/>
  </ComplexType>

I have debugged into processInternal, still debugging it, but am i doing something wrong here?

wog48 commented 1 year ago

I adopted my example to make it similar to yours. I did not get an exception. Please set a break-point in class ODataHandlerImpl at line 85:

image

Step over and see what exception is thrown.

wog48 commented 1 year ago

I hope your question has been answered. I not, please reopen the issue.