This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

one-to-one non-lazy loading but Filters Not Applied.  RSS feed

Sandeep Vaid
Ranch Hand
Posts: 392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We all know that one-to-one associations are non-lazly fetched but during this fetching the filters are not applied.
I debugged hibernate code and found that hibernate finally calls EntityLoader.loadByUniqueKey() method:

public Object loadByUniqueKey(SessionImplementor session, Object key)
throws HibernateException {
return load(session, key, null, null);

I can understand that why filters are not applied because all one-to-one association is automatically non-lazyly fetched
and user may not have specified to fetch this associations and hence not enabled corresponding filters on session and also
not provided filter parameters.

For my case it is very important that i always apply filter as in my case if i don't apply filters, it will return me more than one record as i have one-to-one assocition at Domain model level but
same association is one-to-many at database level and by applying filter i make this one-to-many association at database level as
one-to-one association at Domain model.

Is there somehow, i can apply filters always to one-to-one association or better don;t even create a proxy of one-to-one assocaitons that
i have not asked for?
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!