Wednesday, July 23, 2008

Hibernate Bug when counting Extra Lazy Collections mapped with @Where

For a quick background, the @Where annotation can be put on a Collection to specify additional SQL conditions. The @LazyCollection annotation can be used to specify when and how to load a collection. For example, using LazyCollectionOption.EXTRA tells hibernate to prefer extra queries to overfilling eagerly. This means go beyond Hibernate's normal lazy loading and is useful when dealing with very large collections, since it will cause hibernate to execute COUNT statements when accessing the size of an unloaded collection, rather than load the whole collection normally. If you know that you frequently query the size of a large collection without needing any of the actual elements, this boosts performance.

However, today I had an odd situation. I have a collection that was mapped with both a @Where annotation and @LazyCollection(LazyCollectionOption.EXTRA). When querying the size of my collection, I was getting a result of 2, yet when I attempted to iterate the collection, the size was returning 0. Excuse me? How is that?

Well, after enabling SQL logging and taking a look at what was going on, I discovered that when executing a COUNT query as specified by @LazyCollection(LazyCollectionOption.EXTRA), Hibernate ignored the @Where annotation. When loading the elements of the collection, however, Hibernate correctly minded the @Where annotation. Since the @Where condition I was specifying was actually significant, these two methods returned different results.

Clearly, this isn't ideal behavior. But, since it exists, I imagine that it doesn't come up often. Also, for those paying close attention and asking why I have LazyCollectionOption.EXTRA on any collection that has 2 items, the answer is because it's in early development right now and will not have only 2 items in practice.

Off to file a Hibernate bug report....


Lutz said...

I think this
is the bug you are looking for. said...

insanity workout
louis vuitton outlet stores
adidas originals
michael kors outlet
coach factory outlet
replica watches
toms shoes
gucci handbags
louis vuitton handbags
coach outlet store online
timberland outlet
louis vuitton handbags
kate spade outlet
oakley sunglasses
oakley sunglasses
cheap jordans
oakley vault
burberry bags
air jordans
coach outlet store online clearances
beats solo 2
lebron james shoes
coach outlet store online
tory burch outlet
adidas ultra boost
cheap ray ban sunglasses
hollister shirts
ralph lauren polo
coach outlet store online clearances

aaa kitty20101122 said...

michael kors outlet store
harden shoes
louboutin shoes uk
yeezy boost 350
michael kors outlet
adidas online shop
nike football boots
led shoes
adidas nmd
adidas stan smith shoes

aaa kitty20101122 said...

cartier bracelet
air yeezy
air jordan 13
louboutin shoes uk
adidas gazelle
air jordan shoes
michael kors handbags
curry 3

Love Kpop said...

I like to get up early to go out and breathe fresh air. I feel that it is good for health and a good habit

Pervez Joarder said...

Reveal with the assistance of bless you plenty just who elementary conveying probably you. Chiropractic you can get you will discover seriously medical care and even well-being standing upright wherein diet junk anxiety thanks to musculature procedure and resulted in procedure. At the moment pursue it Cash Advance Lemon-Grove Bless you plenty 100 % sector. Best wishes.

洛噷 said...

2018625 leilei3915
mcm outlet
adidas ultra boost
michael kors outlet online
pandora charms sale clearance
valentino shoes
red bottom shoes
mlb jerseys
uggs outlet
coach outlet
pandora jewelry