question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ManyToOne Mapping throws exception "com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException: Error when creating Referential Constraints"

See original GitHub issue

I am trying to make a simple demo application using this library. I get the above error when using a ManyToOne mapping between my entities.

Entity BeerRating

  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BEER_RATING_ID_GENERATOR")
  @Column(name = "ID", nullable = false, precision = 10)
  private BigDecimal id;

  @ManyToOne
  @JoinColumn(name = "BEER_ID", referencedColumnName = "ID")
  private Beer beer;

Entity Beer

@Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BEER_ID_GENERATOR")
    @Column(name = "ID", nullable = false, precision = 10)
    private BigDecimal id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "BRAND", nullable = false)
    private String brand;

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
wzagrajczcommented, Apr 2, 2019

Hello, I had similar issue and Your solution helped me. Thanks a lot.

However, I wanted to have my relationship bidirectional. So keeping the same entities as in original post I would like to use both

ODataDemo.svc/BeerRatings?$expand=Beer and ODataDemo.svc/Beers?$expand=BeerRating The first one is working perfectly. To achieve the second I added to the Beer something like that

@OneToMany(mappedBy = "beer")
private List<BeerRating> beerRating = new ArrayList<>();

However it does not work - I got error of null code with error message Element BeerId does not correspond to an element in the query result. Do You happen to know what I’m doing wrong? Error message does not tell much to me especially since beerId located in BeerRating have @EdmIgnore annotation.

Thanks

1reaction
wog48commented, Mar 30, 2019

Hello,

in opposite of JPA the JPA Processor needs, as of now, the join column as attribute. You need add the following to BeerRating:

  @EdmIgnore
  @Column(name = "BEER_ID", precision = 10, insertable = false, updatable = false)
  private BigDecimal beerId;

Now the error is gone and BeerId wont appear as property in the metadata document.

Read more comments on GitHub >

github_iconTop Results From Across the Web

olingo jpa processor v4 Exception when using @ManyToOne ...
olingo jpa processor v4 Exception when using @ManyToOne relation. com.sap.olingo.jpa.metadata.core.edm.mapper.exception.ODataJPAModelException: ...
Read more >
Odata V4 String[] mapping - SAP Community
I am currently using PostgreSQL with Odata V4 Olingo and JPA and Hibernate ... "com.sap.olingo.jpa.metadata.core.edm.mapper.exception.
Read more >
com.sap.olingo.jpa.metadata.core.edm.mapper ... - Tabnine
private EdmEnumeration getAnnotation() throws ODataJPAModelException { final EdmEnumeration enumAnnotation = javaEnum.getAnnotation(EdmEnumeration.class); ...
Read more >
EdmSimpleType (olingo-odata2-parent 2.0.10 API)
EdmSimpleType is a primitive type as defined in the Entity Data Model (EDM). There are methods to convert EDM simple types from and...
Read more >
[jira] [Resolved] (OLINGO-1459) Apache Olinge OData service ...
Resolution: Fixed I found the solution > Apache Olinge OData service throws EdmSimpleTypeException when the column in > database is of type ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found