Community
Participate
Working Groups
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).
@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 ... }
@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 ... }
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.
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.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink