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
1
vote
1 answer
ClassCastException with Hibernate ManyToMany Join Query
I have two entities, Reward and User, that are related manytomany as below:
public class Reward {
@Id
@Column(name="reward_id")
private long rewardId;
@ManyToMany(mappedBy="favourite")
@LazyCollection(LazyCollectionOption.FALSE)
…

kovac
- 4,945
- 9
- 47
- 90
1
vote
1 answer
Is there a way to define named queries not within entity classes nor a package-info.java?
Is there a way to register at Hibernate the named queries that don't reside within entity classes or a package-info.java?
At the moment my named queries are defined by means of the annotations org.hibernate.annotations.NamedQuery wrapped in…

Pavel
- 4,912
- 7
- 49
- 69
1
vote
1 answer
JPA NamedQuery use with aggregation functions and group by
I have several records on my database table Foo and I need to aggregate a column to sum its values.
The entity that represents the table is this:
@Entity
@Table(name = "FOO")
@NamedQueries({
@NamedQuery(name = "Foo.total", query = "SELECT f.id,…

TiagoH
- 65
- 10
1
vote
0 answers
Spring boot + Jpa queries from properties file
I am working on spring boot + JPA repository methods. here is my simple query method.
@Query("SELECT g FROM Greeting g where g.text = :text")
Greeting findGreetingByText(@Param("text") String sText);
Is there any way we can configure this query…

Venkatesh Goud
- 616
- 2
- 6
- 22
1
vote
2 answers
JPA query need some guide
I have 3 Entity here A, B and C.
public class A extends B{
int id;
String name;
}
///////////////////////////////////////
public class B implements Serializable{
int id;
String…

Reza P.
- 306
- 2
- 18
1
vote
0 answers
Select many counts in one query using constructor
I'm tryin to count some information and would like to insert them in my db via namedquery using a constructor
This is the code :
@NamedQuery(name = PageEntity.FIND_ALL_PAGES_BY_TYPE, query = "SELECT DISTINCT new…

Laila Bouhouch
- 11
- 3
1
vote
3 answers
How to generate namedQuery by hibernate?
I am working in a project where Java entity classes are generated from db scheme by hibernate tool. I would like to have named queries in the generated classes to be able to find entities by one of their non primary-key field. I would like to have…

Zoltán
- 11
- 2
1
vote
2 answers
JPQL query that returns entities involving a many to many relationship
I need a JPQL query that returns:
All Tweets that I posted
All Tweets that are posted by users whom I follow (this is the many to many part)
I tried something like:
SELECT t
FROM Tweet t
WHERE t.author.id = :userId
OR t.author.id IN (
SELECT…

Lex Bauer
- 15
- 3
1
vote
1 answer
in Grails GORM with Domain inheritence, is it possible to find specific sub-class instances by querying the super-class
class Animal{ ... }
class Tiger extends Animal { ... }
class Deer extends Animal { ... }
Now I wanted to have a namedQuery as
class Animal {
...
static namedQueries = {
findAllAnimalBySpecies{
... some logic for fetch…

devbd
- 431
- 3
- 12
1
vote
1 answer
JPA Group by with multiple field
I am getting following error while using named query blog.findBlogs
"Your select and having clauses must only include aggregates or values that also appear in your grouping clause."
In select clause I have used b.id so it must allow to perform this…

Surendra
- 71
- 2
- 12
1
vote
0 answers
namedQuery - select field from superclass
I've got a problem I couldn't find a sultion, yet. Hope you brains can give me a hint, though :)
The code below shows how it worked till now. But now I want to extend the SELECT by giving back the superColumn2 from the supperClass.
This is my…

0x44656E6E79
- 1,053
- 3
- 14
- 21
1
vote
2 answers
Joining named queries in JPA
I want to know whether I can join 2 named queries in JPA. As an example I have two following named queries
1 - Get all the active users
2 - get all the users for a given company
Is it possible for me to join above two named queries and get
get all…

sameera207
- 16,547
- 19
- 87
- 152
1
vote
1 answer
JPA call to MSSQL stored procedure returns duplicate records
There is a stored procedure in MS SQL server database which I'm calling using JPA. Calling it from the java code, it returns duplicate records:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import…

nenito
- 1,214
- 6
- 19
- 33
1
vote
1 answer
Spring JPA Hibernate how to find array column contains certain elements Named Query
Suppose I have an entity
@Entity
public class Course{
@Id
private Long id;
private String courseName;
//getter and setters
}
now I want to find a Course by its name, hence in its repository, I put a named query,
public interface…

dumb_terminal
- 1,815
- 1
- 16
- 27
1
vote
1 answer
Hibernate generates query with wrong type of @discriminatorvalues of subclasses
I have an inheritance relationship of entities with joined type.
@Entity
@Table(name = "MSM_SUBSCRIPTION")
@DiscriminatorColumn(name = "SUBSCRIPTIONTYPE", discriminatorType = DiscriminatorType.STRING, length = 100)
class subscription…

ds2799
- 59
- 6