fetch subclasses and their associations with one query
demo for simplicity and to avoid being sued :GnuTrolling:
so the question is whether its possible to fetch all the associations to their respective classes when calling the find all method
without eager fetching and avoiding n+1 and without extra queries for getting the associations
16 Replies
⌛
This post has been reserved for your question.
Hey @ayylmao123xdd! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
Can you use a LEFT JOIN?
something like
SELECT FROM Shape s LEFT JOIN FETCH s.vertices ve LEFT JOIN FETCH s.angles an LEFT JOIN FETCH s.sides si
probably
what in the case where i cant edit the repository but i want to add another class
like a circle maybe
but i cant change the repositorys code
(stupid requirements)
if you really want to, you could generate the code
hmmmmmmm
but you probably don't want to
(at build time)
ye that would need entity manager
or make a custom repository
I meant generating the repository interface at compile-time
yea that too
my idea was to
make a strategy for each class
and basically loop over them all
but yeah just using
EntityManager
is probably easierand just add a query from each strategy
and execute it
I think Spring probably allows you to get a list of all entity classes
so you could use that
or just grabbing a list of all the strategies
square strategy etc etc
into a map
whatever you prefer
amazing
ok gonna close
Post Closed
This post has been closed by <@452882919325827074>.