We're updating the issue view to help you get more done. 

Cached HQL query returns a list of null values. (debugged with detailed description)

Description

I have a cached HQL query that is returning a list with all null values. I'm sorry for not including a test case, but I have already debugged the problem and can describe it in detail below.

A bug in hibernate occurs if you try to cache a HQL query that selects an @OneToOne property from a domain object.

The problem is in OneToOneType.disassemble() line 175 in verson 4.2.0. The OneToOneType.disassemble() method returns null, but most likely it should do something similar to what is done in ManyToOneType.disassemble(). I actually fixed the bug in my case by stealing code from ManyToOneType from the disassemble and assemble methods, but I'm pretty sure what I did will break other inverse OneToOne caes. When the OneToOneType.disassemble() method is called from StandardQueryCache.put() line 111, because OneToOneType.disassemble() returns null, then a null is incorrectly placed in the cache resulting in a list of null values being returned from the cache when retrieved later.

If, however, the property that you are selecting in your JPQL query is a @ManyToOne type then there is no problem at all. My work around for now is to use a @ManyToOne on my property instead, but that won't work in all cases, so I will be waiting for one of your smart engineers to fix this bug. Many thanks!

Environment

running on Oracle using Tomcat

Status

Assignee

Unassigned

Reporter

John Jenson

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

4.2.0.Final
4.0.0.Final

Priority

Minor