Wikipedia:Reference desk/Archives/Computing/2018 May 20

= May 20 =

Problem with JPA many-to-many linking
I'm having problems with JPA (Java Persistence API) models and queries at work. Our database model has a many-to-many relationship between two kinds of objects, let's call them  and. So every  can be linked to many different  s and the other way around.

I need to implement an API to this model in JPA queries. I tried making three tables,,   and  , where the third one only consists of two columns:   and  , which link to the   columns of the first two tables, marking which   and which   objects are linked.

I first tried to make this kind of query methods in JPA repositories:

with classes,   and   respectively, each annotated with.

This resulted in an error that  doesn't have an ID field of its own and thus can't be an entity. I removed the  annotation from   and this time I got an error that   is not mapped.

I don't know how to proceed. Am I required to add an ID field to the  object too, even though all it does is link  s and  s together and doesn't possess any information, state or semantics of its own? J I P &#124; Talk 16:11, 20 May 2018 (UTC)