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
0
votes
1 answer
Why in all tutorials write named query in the entity class. It's the logic part
it is good practice don't have any logic in POJO classes, but NamedQuery contains some logic

skilgal
- 172
- 1
- 4
- 14
0
votes
1 answer
JPA: Enums in named queries
I have an Entity like this:
package it.infogroup.vertenze.entities;
import javax.persistence.*;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;
@Entity
@Table(name = "RICHIESTE_ESPORTAZIONE_ISIDORO")
@NamedQueries({
…

Pietro M.
- 379
- 2
- 7
- 16
0
votes
1 answer
Named JPQL Query and Native SQL Query produce different SUMs
i'm dealing with the following scenario:
The Entity Class:
@NamedQuery(
name = "Table.getSum",
query = "SELECT SUM(s.price) FROM Table s WHERE
(s.openingDate >= :openingDate AND s.closingDate <= :closingDate)"
)
The EJB:
…
0
votes
0 answers
Converting SQL query to JPA NamedQuery
I'm trying to implement a Keyword search functionality that returns a List of Keyword entities based on a field text match.
Right now, the query
select * from photo_keywords pk
inner join keywords k on pk.photo_id = k.keyword_id
inner join photos p…

Jason
- 11,263
- 21
- 87
- 181
0
votes
1 answer
Cannot deploy the project, Caused by: Errors in named queries
I have a query. But it does not work. I tested it on Oracle SQL Developer, It worked. So I wrote it in namedquery.
The query is below that works fine on Oracle SQL Developer
SELECT q.* FROM TAKE_EXAM_QUESTION q
INNER JOIN TAKE_EXAM e
on…

Amuna
- 23
- 6
0
votes
1 answer
How can I use JPQL in a NamedQuery to create an entity having a calculated transient attribute?
I have an SQL statement:
SELECT x.SPEED, (6371 * acos(cos(radians(16.65555)))
* cos(radians(LATITUDE)) * cos(radians(LONGITUDE) - radians(54.55555))
+ sin(radians(16.65555)) * sin(radians(LATITUDE))) AS dist
FROM…

du-it
- 2,561
- 8
- 42
- 80
0
votes
1 answer
Spring 2.5 Hibernate 3.5 NamedQuery
I do not use HibernateTemplate, but work with getCurrentSession() in my DAO.
I would like to know how to declare Hibernate named queries in a beans.xml file (I do not use hbm.xml).
And maybe Spring has alternative means to declare Hibernate named…

EugeneP
- 11,783
- 32
- 96
- 142
0
votes
1 answer
Grails Gorm reference a property's (column's) value within a named query?
So... Is there a way to do something like this?
class Kitty {
String name
String nickName
public static String getExpectedNickname(String name) {
return name.replaceAll('Mr. ', '')
}
static namedQueries = {
…

SnoopDougg
- 1,467
- 2
- 19
- 35
0
votes
0 answers
grails gorm named query for many-to-many child empty or contained within list
Why doesn't this work...
void test_get_configurations_whose_descriptors_are_in_list_or_null() {
DeviceConfiguration noDescriptors = DeviceConfiguration(setting1: 1)
DeviceConfiguration hondaCivicConfig = DeviceConfiguration(setting1: 2)
…

SnoopDougg
- 1,467
- 2
- 19
- 35
0
votes
1 answer
update query in hibernate using NamedQuery
Learning Hibernate.Not sure if this is a right question...
I am trying to use NamedQuery for Update in my table
mysql> select * from hib1;
+----+--------+---------+
| id | name | surname |
+----+--------+---------+
| 1 | jack | NULL |
| 2 |…

NoobEditor
- 15,563
- 19
- 81
- 112
0
votes
1 answer
Create a namedQuery to get filtered result
How can I set a parameter as a list of values in a named query, so I can get a filtered resultSet from database?
For example: I want a resultSet which contains only data filtered by code 1, 2, and 3.
In SQL, the query is:
SELECT * FROM…

jMarcel
- 958
- 5
- 24
- 54
0
votes
1 answer
Hibernate Named Query (Select all instances of entity not appearing in other entity)
I have a problem of creating NamedQuery with Hibernate. The problem is I need to select a list of Books not appearing in Orders. My classes looks something like this:
@Entity
@NamedQueries({ @NamedQuery(name = "Book.findAvailable",
query =…

DruidKuma
- 2,352
- 2
- 17
- 20
0
votes
2 answers
Hibernate does change the result set structure (puts Objects[]) into the result set when changing DESC to ASC on a many to many sorted column
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")
…

seba.wagner
- 3,800
- 4
- 28
- 52
0
votes
1 answer
to put some MYSQL to a named query
i need to translate some MySQL code to a JPA named query
example
select * from movies where title like '%matrix%'
would my gues it would
@NamedQuery(name = "Movies.findMoviePart", query = "SELECT c FROM Movies c where c.title LIKE '% :title…

Tom Vercammen
- 1
- 1
0
votes
1 answer
Hibernate Spring Named query to query in a list of objects
I have an Entity called ArtWork and the Entity has attribute List