Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many to many support #22

Closed
nikolay-angeloff opened this issue Dec 15, 2017 · 8 comments
Closed

Many to many support #22

nikolay-angeloff opened this issue Dec 15, 2017 · 8 comments

Comments

@nikolay-angeloff
Copy link

Is there a @manytomany support or how can I achieve such navigation in OData

@wog48
Copy link
Contributor

wog48 commented Dec 17, 2017

That should be possible. In OData you do not directly see that it is a Many To Many relation. You only get to know that it is N:M if you look at both entities, as each navigation property is a collection:
<NavigationProperty Name="..." Type="Collection(...)"

@nikolay-angeloff
Copy link
Author

nikolay-angeloff commented Dec 18, 2017

@wog48

That's true and the navigation property is described well in the $metadata, but when I try to query the navigation items I get "No Join conditions where provided to create sub-query". That's because for ManyToMany in JPA I use Join Table

@manytomany(fetch = LAZY)
@jointable(name = ""production_enterprise.production_enterprise_db::A_Bank_Clients"",
joinColumns = {@joincolumn(name = ""Bank_Id"")},
inverseJoinColumns = {@joincolumn(name = ""Person_Id"")})

And when the processor is building the query it get's the Join Columns which are empty in this case.

@wog48
Copy link
Contributor

wog48 commented Dec 18, 2017

Unfortunately as of now the join columns have to be given as fields in the java pojo. If you do not want it to be part of the OData service you can suppress that by using an additional annotation: @EdmIgnore. Maybe the following example helps:

        @EdmIgnore //Ignore field for metadata generation
	@Column(name = "\"BusinessPartnerID\"")
	private String businessPartnerID;

	@ManyToOne(optional = false, fetch = FetchType.LAZY)
	@JoinColumn(name = "\"BusinessPartnerID\"", insertable = false, updatable = false)
	private BusinessPartner businessPartner;

@nikolay-angeloff
Copy link
Author

@wog48

The join columns are in other table which isn't in the Entity that I'm targeting and the join table isn't represented as an entity itself. So does that mean that the ManyToMany mapping from JPA can't be represented in OData at this point, except with mapping the middle table and with ManyToOne from source and OneToMany from middle to the target entity?

@wog48
Copy link
Contributor

wog48 commented Dec 19, 2017

I like to distinguish between OData an the JPA Processor here:

  • OData, as shortly discussed above, only provides the multiplicity from the perspective of the entity type the navigation property is defined at. With this it is possible to create ManyToMany relations, as long as you do not want to provide the join table on your API. Otherwise you have to model the relations explicit.
  • JPA Processor is, unfortunately, as of now not able to handle join tables, but it is an interesting topic.

@wog48
Copy link
Contributor

wog48 commented Jan 17, 2018

@nikolay-angeloff
The new version 0.2.6 now supports join tables.

@wog48 wog48 closed this as completed Jan 17, 2018
@yathihv
Copy link

yathihv commented Mar 9, 2018

Is this available in maven repository? can you please point me the dependency?

@mjza
Copy link

mjza commented Jul 9, 2020

Any solution for this bug?
https://stackoverflow.com/questions/62809753/olingo-v2-makes-exception-on-entities-with-manytomany-relationships
I am using Olingo V2, but it seems the error coming from JPA is problematic for Olingo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants