1

Would be really interesting if the expand system query option works for any of you when using this library version.

Library and Frameworks combination: Java OData 2 JPA Library 2.0.11 + JPA Hibernate + MySQL

I am trying to use the system query option "expand" (eg. /books?$expand=PublisherDetails) in an OData query. At UriParserImpl#handleSystemQueryOptionExpand - L#796 occurs a NPE cause the edmType of the fetched property at L#792 is null

If i want to query data from another table using recursive queries (eg. books('id')/PublisherDetails) i am running into the same problem in a different way. UriParserImpl#handleNavigationProperties - L#299

UriParserImpl java class in library: https://github.com/apache/olingo-odata2/blob/master/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/uri/UriParserImpl.java


Persistence Entities:

Book

@Entity(name = "book")
public class Book implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(length = 100)
    protected String bookID;
    .
    .
    .
    @ManyToOne(cascade = { CascadeType.REFRESH })
    private Publisher publisher;

    public String getBookID() {
        return bookID;
    }

    public void setBookID(final String bookID) {
        this.bookID= bookID;
    }

    public Publisher getPublisher() {
        return publisher;
    }

    public void setPublisher(final Publisher publisher) {
        this.publisher = publisher;
    }
    .
    .
    .
}

Publisher

@Entity(name = "publisher")
public class Publisher implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(length = 100)
    private String id;
    .
    .
    .
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "publisher")
    private List<Book> books;

    public String getId() {
        return id;
    }

    public void setId(final String id) {
        this.id = id;
    }
    .
    .
    .
}

My Navigation Properties and Associations would look fine when fetching it via $metadata..

Navigation Property:

<NavigationProperty Name="PublisherDetails" Relationship="persistence-unit-name.book_Publisher_Many_ZeroToOne0" FromRole="book" ToRole="Publisher"/>

Association:

 <Association Name="book_Publisher_Many_ZeroToOne0">
        <End Type="persistence-unit-name.book" Multiplicity="*" Role="book"/>
        <End Type="persistence-unit-name.Publisher" Multiplicity="0..1" Role="Publisher"/>

EntityContainer:

<EntityContainer Name="persistence-unit-nameContainer" m:IsDefaultEntityContainer="true">
        <EntitySet Name="books" EntityType="persistence-unit-name.book"/>
        <EntitySet Name="publishers" EntityType="persistence-unit-name.publisher"/></EntityContainer>

And... is it normal that i don't have foreign key Properties in my EntitySets?

Tips on what i might be doing wrong are much appreciated.

  • Can you filter based on an string column? Could you please share your code in a github repository? It is interesting. I have more or less same problem. It seems olingo version 2.0.11 is not stable https://stackoverflow.com/questions/62122778/set-databes-dialect-in-spring-boot-starter-web-version-2-3-0-for-hibernate – MJBZA Jun 01 '20 at 14:21
  • I could not filter on a string column at first - seems like i had the same problem that you have right now.. i fixed it.. not really neat but it works. I don't know how your database queries are executed in detail - in my case, hibernate generates a sql query that i can insepct and modify if needed: Hibernate StatementInspector -> overriting inspect method and correcting the 2.0.11 odata library issue by replacing the invalid escape statement – kstackflowacc Jun 02 '20 at 08:43
  • I guess that this should also work for you since you are using hibernate too - question is, if there is a better way to solve the issue :) – kstackflowacc Jun 02 '20 at 08:49
  • sorry But I didn't understand what you did exactly. Could you please provide a detailed code answer here or on my question? – MJBZA Jun 02 '20 at 08:51

0 Answers0