[ 
https://issues.apache.org/jira/browse/OLINGO-1467?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Mahdi Ansari updated OLINGO-1467:
---------------------------------
    Description: 
I have made an OData server with Spring-boot, JPA, Hibernate and Olingo2.

There is a *{{ManyToMany}}* relationship between {{User}} and {{Role}} entities.
{code:java}
// In User entity 
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, 
CascadeType.MERGE}) 
@JoinTable(name = "user_authority", 
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = 
"user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id", 
referencedColumnName = "role_id")}) 
private Set<Role> roles = new HashSet<>();{code}
and
{code:java}
// In Role entity 
//bi-directional many-to-many association to User 
@ManyToMany(mappedBy="roles", fetch = FetchType.LAZY) 
@JsonIgnore 
private Set<User> users = new HashSet<>();{code}
I am using Olingo {{V2.0.11}} and spring boot version {{2.3.0.RELEASE}}.

When I try to see the list of Roles in my odata endpoint I can easily do it, 
however when I try to see list of Users like:
{code:java}
http://localhost:9090/odata.svc/UserSet{code}
Then I get the following error:
{code:java}
<?xml version='1.0' encoding='UTF-8'?> 
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";> 
<code/> 
<message xml:lang="en">Missing message for key 
'org.apache.olingo.odata2.api.edm.EdmSimpleTypeException.PROPERTY_VALUE_FACETS_NOT_MATCHED'!</message>
 
</error>{code}
The interesting point is if I only retrieve one User like:
{code:java}
http://localhost:9090/odata.svc/UserSet(1)?$format=json&$expand=Roles {code}
Then I can see the result, even as you saw I could expand the Roles 
relationship:

{{{{ }}}}
{{{}}
{{     "d": {}}
{{         "__metadata": }}{{{             "id": 
"http://localhost:9090/odata.svc/UserSet(1L)",             "uri": 
"http://localhost:9090/odata.svc/UserSet(1L)",             "type": 
"me.cimply.User"         }}}{{,}}
{{         "active": true,}}
{{         "createdAt": "/Date(1594283306126)/",}}
{{         "email": "a...@gmail.com",}}
{{         "emailVerified": true,}}
{{         "firstName": "Guest",}}
{{         "id": "1",}}
{{         "lastName": "  ",}}
{{         "photoContent": null,}}
{{         "updatedAt": "/Date(1594283306126)/",}}
{{         "username": "a...@gmail.com",}}
{{         "Answers": {}}
{{             "__deferred": }}{{{                 "uri": 
"http://localhost:9090/odata.svc/UserSet(1L)/Answers"             }}}{{        
},}}
{{         "Roles": {}}
{{             "results": [}}
{{                 {}}
{{                     "__metadata": }}{{{                         "id": 
"http://localhost:9090/odata.svc/Roles(2L)",                         "uri": 
"http://localhost:9090/odata.svc/Roles(2L)",                         "type": 
"me.cimply.Role"                     }}}{{,}}
{{                     "id": "2",}}
{{                     "role": "ROLE_ADMIN",}}
{{                     "users": {}}
{{                         "__deferred": }}{{{                             
"uri": "http://localhost:9090/odata.svc/Roles(2L)/users"                        
 }}}{{                    }}}
{{                 },}}
{{                 {}}
{{                     "__metadata": }}{{{                         "id": 
"http://localhost:9090/odata.svc/Roles(1L)",                         "uri": 
"http://localhost:9090/odata.svc/Roles(1L)",                         "type": 
"me.cimply.Role"                     }}}{{,}}
{{                     "id": "1",}}
{{                     "role": "ROLE_USER",}}
{{                     "users": {}}
{{                         "__deferred": }}{{{                             
"uri": "http://localhost:9090/odata.svc/Roles(1L)/users"                        
 }}}{{                    }}}
{{                 }}}
{{             ]}}
{{         },}}
{{         "Surveys": {}}
{{             "__deferred": }}{{{                 "uri": 
"http://localhost:9090/odata.svc/UserSet(1L)/Surveys"             }}}{{        
}}}
{{     }}}
{{ }}}
{{ {{  }}}}

I am not sure the error comes from JPA or from Olingo. Anyone else has similar 
experiences with Olingo V2 for defining ManyToMany relationship?

  was:
I have made an OData server with Spring-boot, JPA, Hibernate and Olingo2.

There is a *{{ManyToMany}}* relationship between {{User}} and {{Role}} entities.
{code:java}
// In User entity 
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, 
CascadeType.MERGE}) 
@JoinTable(name = "user_authority", 
joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = 
"user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id", 
referencedColumnName = "role_id")}) 
private Set<Role> roles = new HashSet<>();{code}
and
{code:java}
// In Role entity 
//bi-directional many-to-many association to User 
@ManyToMany(mappedBy="roles", fetch = FetchType.LAZY) 
@JsonIgnore 
private Set<User> users = new HashSet<>();{code}
I am using Olingo {{V2.0.11}} and spring boot version {{2.3.0.RELEASE}}.

When I try to see the list of Roles in my odata endpoint I can easily do it, 
however when I try to see list of Users like:
{code:java}
http://localhost:9090/odata.svc/UserSet{code}
Then I get the following error:
{code:java}
<?xml version='1.0' encoding='UTF-8'?> 
<error xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";> 
<code/> 
<message xml:lang="en">Missing message for key 
'org.apache.olingo.odata2.api.edm.EdmSimpleTypeException.PROPERTY_VALUE_FACETS_NOT_MATCHED'!</message>
 
</error>{code}
The interesting point is if I only retrieve one User like:
{code:java}
http://localhost:9090/odata.svc/UserSet(1)?$format=json&$expand=Roles {code}
Then I can see the result, even as you saw I could expand the Roles 
relationship:

{{ }}
{{}}
{
    "d": {
        "__metadata": {
            "id": "http://localhost:9090/odata.svc/UserSet(1L)",
            "uri": "http://localhost:9090/odata.svc/UserSet(1L)",
            "type": "me.cimply.User"
        },
        "active": true,
        "createdAt": "/Date(1594283306126)/",
        "email": "a...@gmail.com",
        "emailVerified": true,
        "firstName": "Guest",
        "id": "1",
        "lastName": "  ",
        "photoContent": null,
        "updatedAt": "/Date(1594283306126)/",
        "username": "a...@gmail.com",
        "Answers": {
            "__deferred": {
                "uri": "http://localhost:9090/odata.svc/UserSet(1L)/Answers"
            }
        },
        "Roles": {
            "results": [
                {
                    "__metadata": {
                        "id": "http://localhost:9090/odata.svc/Roles(2L)",
                        "uri": "http://localhost:9090/odata.svc/Roles(2L)",
                        "type": "me.cimply.Role"
                    },
                    "id": "2",
                    "role": "ROLE_ADMIN",
                    "users": {
                        "__deferred": {
                            "uri": 
"http://localhost:9090/odata.svc/Roles(2L)/users"
                        }
                    }
                },
                {
                    "__metadata": {
                        "id": "http://localhost:9090/odata.svc/Roles(1L)",
                        "uri": "http://localhost:9090/odata.svc/Roles(1L)",
                        "type": "me.cimply.Role"
                    },
                    "id": "1",
                    "role": "ROLE_USER",
                    "users": {
                        "__deferred": {
                            "uri": 
"http://localhost:9090/odata.svc/Roles(1L)/users"
                        }
                    }
                }
            ]
        },
        "Surveys": {
            "__deferred": {
                "uri": "http://localhost:9090/odata.svc/UserSet(1L)/Surveys"
            }
        }
    }
}
{{  }}
 
 
  

 

I am not sure the error comes from JPA or from Olingo. Anyone else has similar 
experiences with Olingo V2 for defining ManyToMany relationship?


> Olingo V2 makes exception on entities with ManyToMany relationships
> -------------------------------------------------------------------
>
>                 Key: OLINGO-1467
>                 URL: https://issues.apache.org/jira/browse/OLINGO-1467
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata2-jpa
>    Affects Versions: V2 2.0.11
>         Environment: Spring-boot, Hibernate
>            Reporter: Mahdi Ansari
>            Priority: Major
>
> I have made an OData server with Spring-boot, JPA, Hibernate and Olingo2.
> There is a *{{ManyToMany}}* relationship between {{User}} and {{Role}} 
> entities.
> {code:java}
> // In User entity 
> @ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, 
> CascadeType.MERGE}) 
> @JoinTable(name = "user_authority", 
> joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = 
> "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id", 
> referencedColumnName = "role_id")}) 
> private Set<Role> roles = new HashSet<>();{code}
> and
> {code:java}
> // In Role entity 
> //bi-directional many-to-many association to User 
> @ManyToMany(mappedBy="roles", fetch = FetchType.LAZY) 
> @JsonIgnore 
> private Set<User> users = new HashSet<>();{code}
> I am using Olingo {{V2.0.11}} and spring boot version {{2.3.0.RELEASE}}.
> When I try to see the list of Roles in my odata endpoint I can easily do it, 
> however when I try to see list of Users like:
> {code:java}
> http://localhost:9090/odata.svc/UserSet{code}
> Then I get the following error:
> {code:java}
> <?xml version='1.0' encoding='UTF-8'?> 
> <error 
> xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata";> 
> <code/> 
> <message xml:lang="en">Missing message for key 
> 'org.apache.olingo.odata2.api.edm.EdmSimpleTypeException.PROPERTY_VALUE_FACETS_NOT_MATCHED'!</message>
>  
> </error>{code}
> The interesting point is if I only retrieve one User like:
> {code:java}
> http://localhost:9090/odata.svc/UserSet(1)?$format=json&$expand=Roles {code}
> Then I can see the result, even as you saw I could expand the Roles 
> relationship:
> {{{{ }}}}
> {{{}}
> {{     "d": {}}
> {{         "__metadata": }}{{{             "id": 
> "http://localhost:9090/odata.svc/UserSet(1L)",             "uri": 
> "http://localhost:9090/odata.svc/UserSet(1L)",             "type": 
> "me.cimply.User"         }}}{{,}}
> {{         "active": true,}}
> {{         "createdAt": "/Date(1594283306126)/",}}
> {{         "email": "a...@gmail.com",}}
> {{         "emailVerified": true,}}
> {{         "firstName": "Guest",}}
> {{         "id": "1",}}
> {{         "lastName": "  ",}}
> {{         "photoContent": null,}}
> {{         "updatedAt": "/Date(1594283306126)/",}}
> {{         "username": "a...@gmail.com",}}
> {{         "Answers": {}}
> {{             "__deferred": }}{{{                 "uri": 
> "http://localhost:9090/odata.svc/UserSet(1L)/Answers"             }}}{{       
>  },}}
> {{         "Roles": {}}
> {{             "results": [}}
> {{                 {}}
> {{                     "__metadata": }}{{{                         "id": 
> "http://localhost:9090/odata.svc/Roles(2L)",                         "uri": 
> "http://localhost:9090/odata.svc/Roles(2L)",                         "type": 
> "me.cimply.Role"                     }}}{{,}}
> {{                     "id": "2",}}
> {{                     "role": "ROLE_ADMIN",}}
> {{                     "users": {}}
> {{                         "__deferred": }}{{{                             
> "uri": "http://localhost:9090/odata.svc/Roles(2L)/users"                      
>    }}}{{                    }}}
> {{                 },}}
> {{                 {}}
> {{                     "__metadata": }}{{{                         "id": 
> "http://localhost:9090/odata.svc/Roles(1L)",                         "uri": 
> "http://localhost:9090/odata.svc/Roles(1L)",                         "type": 
> "me.cimply.Role"                     }}}{{,}}
> {{                     "id": "1",}}
> {{                     "role": "ROLE_USER",}}
> {{                     "users": {}}
> {{                         "__deferred": }}{{{                             
> "uri": "http://localhost:9090/odata.svc/Roles(1L)/users"                      
>    }}}{{                    }}}
> {{                 }}}
> {{             ]}}
> {{         },}}
> {{         "Surveys": {}}
> {{             "__deferred": }}{{{                 "uri": 
> "http://localhost:9090/odata.svc/UserSet(1L)/Surveys"             }}}{{       
>  }}}
> {{     }}}
> {{ }}}
> {{ {{  }}}}
> I am not sure the error comes from JPA or from Olingo. Anyone else has 
> similar experiences with Olingo V2 for defining ManyToMany relationship?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to