inca/circumflex

ignore

Closed this issue · 4 comments

ignore

inca commented

Nope. Prefetching is far more complex than adding a FROM clause. Moreover, prefetching is totally impossible with some query clauses (e.g. LIMIT and OFFSET).

inca commented

Okay, I'll take a look. But not in 2.0, maybe in later releases.

inca commented

When 3 years ago I had a small database (around 20 tables and 8 views), Hibernate's prefetching was my safety belt. As our corporate database has grown up to around 80 tables it became a nightmare: it is virtually impossible to debug these implicit things: you either get queries with 12-15 join clauses (imagine how fast they are) or you get LazyInitializationException in most unpredictable places.

Lessons learned: we made our ORM as close to original SQL as possible (maybe we'll continue working in that direction). If you use SQL queries, you'll get precisely the query you expect. No implicit joins. For those who can't live without prefetching we made Criteria API.

However, I don't recommend getting yourself too deep into prefetching. The capabilities of querying are limited: you can't order, filter or limit fetched data. Determine exact data required by your view and query it instead. Apply ordering and limits as required. Do your best to break complex logic into peaces. Do not fetch the entire data hierarchy if you don't show everything at once, do partial requests instead. Short and fast transactions usually withstand more load than their counterparts.

Taking that into consideration, I am marking this one as "wontfix". All objections are welcome for discussion in google groups. But please do your best to prove your point, to predict consequences and to look for alternative solutions before you go.

inca commented

There is no way to add FETCH method to SQL DSL (this feature is totally incompatible with projections).

I can add fetch method to RelationNode which creates Criteria implicitly so that API calls could be a bit shorter:

Country.AS("co").fetch(City.country).list
// equivalent to
Country.AS("co").criteria.prefetch(City.country).list

This would only save one word of typing and I highly doubt it is reasonable. Or did I miss something?