Home JPA find grandparent entity given only child unique key
Reply: 0

JPA find grandparent entity given only child unique key

user6690 Published in September 20, 2018, 12:45 pm

I am using JPA & MySQL.

If I have a bunch of entities that are related as follows:

  • Grandparent_entity has many Parent_entity (OneToMany). Persisted with a join table.
  • Parent_entity has one Child_entity (OneToOne). Persisted with child_uuid in parent table.

If I am given only the child unique key, how do I get the grandparent entity?

My idea is a query with 3 joins - child to parent, parent to join table, join table to grandparent. Is this the best way?

share|improve this question
  • JPQL or CriteriaQuery? Can you show your Entities how they are mapped to each other? – pirho Feb 12 at 19:37
  • JPQL - i think i cracked it following this: vladmihalcea.com/hibernate-facts-multi-level-fetching – Dee Feb 12 at 19:47

2 Answers 2

active oldest votes
up vote 0 down vote
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34549 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO