Given the following entity definition (see that the named query defines no resultClass):
@Entity
@Table(name = "posts")
@NamedNativeQuery(name = "Post.findById", query = "SELECT * FROM posts")
public class Post implements Serializable {
@Id
@GeneratedValue
private Long id;
}
And a request to create a named query specifying the result class:
em.createNamedQuery("Post.findById", Post.class).getResultList();
Causes an ArrayIndexOutOfBoundsException at org.hibernate.internal.AbstractSharedSessionContract.resultClassChecking(AbstractSharedSessionContract.java:815) "resultClassChecking" checks that there's only one result class defined, but doesn't account for the case when no result is defined. As a user, I'd expect a simple error saying that the requested named query exists, but its result is not compatible. I'm marking this issue as improvement as it is not a bug per se (expected behavior is to fail, just with a more clear message). Not sure if this is correct. |