hibernate - HQL returns duplicate objects -


i have 2 questions regarding hql usage

  1. i have query below, returns duplicate rows/objects, adding distinct keyword solves problem can explain, why need distinct here, can't without it?

    select st state st inner join fetch st.cities 
  2. the hql documentation says

    a fetch join not need assign alias, because associated objects should not used in clause (or other clause).

    but why can't use associated objects in clause, if want eagerly fetch want add condition how it?

  1. simply because that's how hql , jpql specified: 1 element returned per row of jdbc resultset, unless use distinct.

  2. because if allowed add restrictions on fetched entities, break invariants of entities themselves, hibernate, , own code, assume verified: cities returned state.getcities() cities of state. of them. not ones happen obey criteria of random query.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -