简体   繁体   中英

Join multiple tables for one entity with JPA?

I was wondering if it was possible to create an entity that fetches data from multiple tables.

I have an entity based on a TableA.

The particularity is that I also need data from TableD, which is linked to TableC, which is linked to TableB finally linked to TableA with TableA id

I am fully aware that I could create an entity on TableB,C,D. But I don't need ANY data on those tables except on TableD. B and C are just "a path to follow".

http://img11.hostingpics.net/pics/878537schema.png

I saw the @SecondaryTables annotation that I could use on EntityA but it seems like you can only join with the PK of EntityA.

If you know a solution that will prevent me from creating useless entities, I'd be grateful.

You can link each entity through inheritance strategy InheritanceType.JOINED. Then you can get all values of parent classes in child class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM