3 ms·
def user = User.findById(25) return user.getLocation().getAddress().getState() What happened during that execution? Was that 1 query or 50? Would it ha
by columbo 14y ago
def user = User.findById(25)
return user.getLocation().getAddress().getState()
What happened during that execution? Was that 1 query or 50? Would it have been better to write a specific sql statement?
To me, this describes the biggest challenges with using or not using ORMs. I don't think there is an easy answer.
- moondowner 14y agoAt least in Hibernate, you can set to print the actual queries in console (or text file, depending how your logger is set). http://stackoverflow.com/a/2538954/228692 http://stackoverflow.com/a/2538954/228692 That way, during development you can see which are the actual statements executed. I say during development because after that, in production, you'd be better off filling log files with these stuff :) And I can answer your question (for Hibernate), that will be one query.
- phillmv 14y ago>I don't think there is an easy answer. Uhm, ActiveRecord at least will print the SQL it generated. If you think it's inefficient, you can just… write your own sql that maps out to that query. With Arel/scopes, they're also composable and lazy loaded. What's not to like?