A Hibernate (and NHibernate) feature that allows for both HQL and SQL queries to be written in the mapping document, keyed by a name. The main advantage is that your query is now residing in the same place as the definition of your mappings, instead of in your Java/C#/VB.NET/... code.
Questions tagged [named-query]
521 questions
5
votes
1 answer
Check if a specific named parameter exists or not in hibernate named query
I am trying to develop a application where I have a common DAO as EntityDao.
That class has a method executeNamedQuery as follows.
public List executeNamedQuery(String queryName) {
Query query =…

Partha Sarathi Ghosh
- 10,936
- 20
- 59
- 84
5
votes
2 answers
Getting 'Named query not found' with Spring framework
I have a Java class (Entity) with a set of named queries. When the Spring tries to inject the related bean, it is not finding one of the queries.
As example:
@NamedQueries({
@NamedQuery(name = "Query1", query = "..."),
…

Felipe Arenales
- 991
- 1
- 8
- 19
5
votes
5 answers
Can we define all the Named Queries at one place like some property file instead of writing in the entity class
How to Define All Named Queries in One place (like class) instead of writing the NamedQuery in top of Entity class.
For Example i have a base class. In this class i can define all named queries.
Base.java
@Entity
@NamedQueries({
…

Ranga Reddy
- 2,936
- 4
- 29
- 41
5
votes
1 answer
MappingException: Named query not known
Trying to learn Hibernate, i am trying to learn how to execute NamedQuries but evertime i am getting Exception in thread "main" org.hibernate.MappingException: Named query not known.Please help me out here
Error (only the message, not showing…

NoobEditor
- 15,563
- 19
- 81
- 112
5
votes
2 answers
Jpa namedquery with left join fetch
this is my namedquery:
@NamedQuery(
name = "User.findOneWithLists",
query = "SELECT u FROM User u "
+ "LEFT JOIN FETCH u.aTemplates "
+ "LEFT JOIN FETCH…

user3296520
- 361
- 2
- 4
- 12
5
votes
4 answers
How to make this select * from two joined tables query in HQL form?
I had two hibernate entity here with annotation:
@Entity
@Table(name = "CLIENT")
public class Client {
private Long pkClient;
private String name;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name="PK_CLIENT")
…

null
- 8,669
- 16
- 68
- 98
4
votes
2 answers
NamedQuery defined in DAO annotation not found by Hibernate session factory
I use Spring along with Hibernate. In my DAO, I defined a NamedQuery which is not found by the session factory, although I have added the package of that DAO to the packagesToScan.
My DAO:
/**
*
*/
package org.lalala.service.mytest;
import…

rainer198
- 3,195
- 2
- 27
- 42
4
votes
1 answer
Parameter named query testing with mockito
I want to write a Junit test for my dao, but I have a problem. Here is the method I want to test:
public boolean boo(final String param) {
final Query query = this.entityManager.createNamedQuery("queryName");
…

Oleksandr
- 2,346
- 4
- 22
- 34
4
votes
0 answers
Named query with a Pageable parameter
LOG.warn("Finder method {} is backed by a NamedQuery but contains a Pageable parameter! Sorting delivered this Pageable will not be applied!", method)
I'm getting the warning above. What is the reason of the warn?

gfg007
- 171
- 8
4
votes
1 answer
Call namedQuery inside a criteria in controller
Is possible to call namedQuery on grails inside a controller? I know that I can call a namedQuery inside another namedQuery, but i dont want to do that. Any ideas? Thanks
User.groovy
static namedQueries = {
filterUsers{
eq("age",…

Luccas
- 4,078
- 6
- 42
- 72
4
votes
1 answer
How do Hibernate event listeners behave using HQL (named queries)?
I create a lot of hibernate event listeners, to catch all database events like load, persist, update, delete etc. All events will be caught, but named queries will not be caught by my load event listener and I would like to ask, what I need to…

moohkooh
- 917
- 1
- 10
- 25
4
votes
3 answers
How can I handle a possibly empty parameter List when using a named query in NHibernate?
I'm having issues on handling a situation where a list of parameters sent to a named query in NHibernate is empty.
This is an example of my situation:

BCdotWEB
- 1,009
- 1
- 14
- 35
4
votes
2 answers
Grails named queries not working with "in" statement
I have a Grails application (2.2.4). Where in domain class I have looks like this
class Author implements Serializable {
....
static hasMany = [
book : Book
]
static namedQueries = {
hasGenre {genreNameList ->
…

Visahan
- 1,130
- 2
- 14
- 35
4
votes
1 answer
How to comment (javadoc) NamedQueries
Assume there are some named queries in an entity, how should those named queries be commented? Is there a way to map them into the created javadoc?
@Entity
@NamedQueries({
@NamedQuery(name="Country.findAll",
…

aldebaran-ms
- 666
- 6
- 18
4
votes
1 answer
Pageable sorting not working for Spring Data JPA when using named queries
I got to grips with using Spring Data JPA however I stumbled upon an issue, searched all the net but still didn't find an answer. I got the repository working and even the paging and sorting. However, it seems that when I do the same, but…

Christopher Grech
- 41
- 1
- 3