Bug 351481 - QueryHints.CACHE_USAGE=CheckCacheThenDatabase changes return value/class of a SELECT/JOIN
Summary: QueryHints.CACHE_USAGE=CheckCacheThenDatabase changes return value/class of a...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-07 14:32 EDT by Richard A. Sitze CLA
Modified: 2022-06-09 10:21 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard A. Sitze CLA 2011-07-07 14:32:53 EDT
Have verified this behavior on both EclipseLink 2.0.0 and Eclipse 2.3.0.

I have the following name query defined on an Entity:

**********
@NamedQuery(name = "Definition.findDefault",
                    query = "SELECT DISTINCT d"
                            + " FROM Category c JOIN c.definitions d"
                            + " WHERE c.active=true AND d.active=true AND d.defaultInCategory=true",
                    hints = {@QueryHint(name = QueryHints.CACHE_USAGE, value = CacheUsage.CheckCacheThenDatabase)})
**********

Note the use of a JOIN, and that the (single) result returned by the SELECT is from the right side of that JOIN.
With the QueryHint in play, EclipseLink incorrectly returns 'c' (the Category).
Without the QueryHint, EclipseLink correctly returns 'd' (the Definition).
Comment 1 Richard A. Sitze CLA 2011-07-07 15:19:28 EDT
@Entity
@Table(name = "extra_definition")
@NamedQueries({...as above...})
public class Definition implements Serializable, Definition
{
    private static final long                          serialVersionUID = 1L;


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer                                    id;


    @Column(name = "active")
    private boolean                                    active;

    @Column(name = "name")
    private String                                     name;

    @Column(name = "default_in_category")
    private boolean                                    defaultInCategory;


    @ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "category")
    private Category              category;

... bean stuff ...
}
Comment 2 Richard A. Sitze CLA 2011-07-07 15:19:44 EDT
@Entity
@Table(name = "extra_category")
public class TableauxSubItemCategoryEntity implements Serializable
{
    private static final long                     serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer                               id;

    @Column(name = "name")
    private String                                name;

    @Column(name = "active")
    private boolean                               active           = true;


    @OneToMany(mappedBy = "category")
    @OrderBy("sortCode, name")
    private List<TableauxSubItemDefinitionEntity> definitions;

... bean stuff ...
}
Comment 3 Richard A. Sitze CLA 2011-07-07 15:24:10 EDT
The query was changed (and makes a lot more sense) to use the reverse relationship, placing the desired/target entity type on the left of the join:

***********
query = "SELECT DISTINCT d"
      + " FROM Definition d JOIN d.category c"
      + " WHERE c.active=true AND d.active=true AND d.defaultInCategory=true"
***********

This works just fine with the QueryHint in play.
Comment 4 Tom Ware CLA 2011-07-15 10:54:25 EDT
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 5 Eclipse Webmaster CLA 2022-06-09 10:16:19 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 6 Eclipse Webmaster CLA 2022-06-09 10:21:54 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink