database - Create a (Many to Many) Many relationship using JPA and Java EE -


i trying create relationship using jpa. confusing , can't wrap head around it. it's weird because think jpa limits this.

here's idea:

a relationship...

tablea    pk    ida 

between...

tableb    pk    idb 

forms table:

tablea_tableb    pfk   ida    pfk   idb 

and relate tablea_tableb (or table generated) table, tablec:

tablec    pk    idc 

forms table:

tablea_tableb_tablec    pfk   ida    pfk   idb    pfk   idc 

and want add attribute table tablea_tableb_tablec called value. it'll this:

tablea_tableb_tablec    pfk   ida    pfk   idb    pfk   idc          attribute 

however, annotation @manytomany() rather limiting. can join table 1 key another.

i can't find decent examples online. yeah.

thanks in advance.

the manytomany-annotation meant "plain" relationships, without additional information.

i recommend this:

  • create new persistent entity class (i.e. "tableabcrelationship")
  • link 3 existing entity classes new entity class, using 3 onetomany-annotations @ existing classes , 3 manytoone-annotations in new class
  • add additional field "attribute" in new entity class
  • change existing references

depending on existing code, might effort refactor everything...


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -