I have the following two different HQL statements.
My Data Structure looks like this:
User
@Entity (name = "User")
public class User
{
@Id
@GeneratedValue
@Column (name = "id")
private int id;
@Column (name = "user_name")
private String username;
@Column (name = "password")
private String password;
@Column (name = "enabled")
private boolean enabled;
@ManyToMany (targetEntity = Role.class, cascade =
{
CascadeType.ALL
})
@JoinTable (name = "user_role", joinColumns =
{
@JoinColumn (name = "user_id")
}, inverseJoinColumns =
{
@JoinColumn (name = "role_id")
})
private Set<Role> roles;
/* getters and setters)
}
To cut it short the only difference between the two queries is that one is ASC the other is DESC
@NamedQuery (name = "user.getUsersOrderByRoleAsc",
query = "FROM User as u left outer join u.roles roles WHERE u.username like :username ORDER BY roles.name ASC"),
@NamedQuery (name = "user.getUsersOrderByRoleDesc",
query = "FROM User as u left outer join u.roles roles WHERE u.username like :username ORDER BY roles.name DESC"),
The query for ASC returns: A list of Users -> As I would expect.
The query of DESC returns: An List of Object[], and in each object the [0] is the User, while the [1] is just another null object.
That does not make any sense to me. How can simply changing ASC to DESC change the structure of the result set ?
I am using Hibernate 4.3.6.Final.