Questions tagged [named-query]

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.

521 questions
3
votes
2 answers

Hibernate Named Query - join 3 tables

I have 3 beans: Organization, Role, User Role - Organization relation - @ManyToOne Role - User relation - @ManyToMany Organization : @Entity @Table(name = "entity_organization") public class Organization implements Serializable { …
BraginiNI
  • 576
  • 1
  • 16
  • 30
3
votes
1 answer

Define Named Query in NHibernate Fluent Mapping without .hbm or xml files

Currently I am using NHibernate and Fluent mapping for as ORM. I use named queries to call stored procedures. The named queries are saved in .hbm files. e.g:
frictionlesspulley
  • 11,070
  • 14
  • 66
  • 115
3
votes
3 answers

Is it good practice to use @NamedQuery for single column selects (J2EE/JPA, Hibernate)

I'm working on J2EE 6 codebase that uses Hibernate as its persistence provider. My experience lies more in Spring and I'm quite new to JPA annotations and similar, but I've noticed a lot of this in all the entity classes, and it surprises me - I…
Peter
  • 29,498
  • 21
  • 89
  • 122
3
votes
1 answer

Hibernate pagination not working when using native queries (Named query exists but its result type is not compatible)

I have a two named native queries in my orm.xml, one for retrieving the data, and one for doing the count for my pagination: select count(*) from from person …
Erik Pragt
  • 13,513
  • 11
  • 58
  • 64
3
votes
5 answers

Using Unmapped Class with NHibernate Named Query

I'm using a custom named query with NHibernate which I want to return a collection of Person objects. The Person object is not mapped with an NHibernate mapping which means I'm getting the following…
lomaxx
  • 113,627
  • 57
  • 144
  • 179
3
votes
1 answer

JPA2 error validation : state field cannot be resolved

I have a error that I can not get rid of, but the code works in the same time. @NamedQuery(name="getDocteur", query="SELECT d FROM Clinique cli, IN (cli.docteurs) AS d WHERE cli.clinique_ID=:clinique_ID AND d.docteur_ID=:docteur_ID") the Error…
Sebastien Dionne
  • 757
  • 2
  • 19
  • 34
3
votes
4 answers

Hibernate: Mapping custom column names in stored procedure named query

I currently have the following named query that wraps around a stored procedure:-
limc
  • 39,366
  • 20
  • 100
  • 145
3
votes
1 answer

How to check at runtime if a NamedNativeQuery was declared

In Hibernate, is there a way to check if a given @NamedNativeQuery exists before calling: Session.getNamedQuery("queryName"); I am composing the name of the Query at runtime, so I need a way to find if it exists, in order to avoid the following…
Andrea Caloni
  • 135
  • 2
  • 6
3
votes
0 answers

hibernate migration from 4 to 5

I have used Hibernate 4 since a long time and now I need to upgrade to hibernate 5 and I have some trouble now with some named query: ERROR: HHH000177: Error in named query: findByNumHeure org.hibernate.hql.internal.ast.QuerySyntaxException:…
Chatis
  • 47
  • 2
  • 11
3
votes
1 answer

Combine NamedQuery and Criteria in Hibernate

I use Hibernate in a storefinder application. For the proximity search in SQL I use the haversine formula. Because this is a bit messy SQL I created a named SQL query in my .hbm.xml File for this. SELECT location.*, ( 3959 * acos( cos(…
apropoz
  • 327
  • 1
  • 3
  • 9
3
votes
1 answer

Hibernate errors in named queries

I am trying to pull information from a table where the current date is between the first and last day of any given month. I am getting a runtime error "Errors in named queries: Department.byDate" I am providing you with what code I think could be…
Craig
  • 364
  • 1
  • 3
  • 25
3
votes
2 answers

Grails domain Named query for a list of string

I have a simple Grails application. I have domains as below class Author implements Serializable { .... static hasMany = [ book : Book ] } class Book implements Serializable{ Author author Genres genres static belongsTo…
Visahan
  • 1,130
  • 2
  • 14
  • 35
3
votes
2 answers

Trouble with hibernate's named query

I am new to hibernate and I am having some trouble with the named query annotation. My code is as follows and is more or less generated by NetBeans The BasicUser class: package wmc.model; import java.io.Serializable; import…
AnAmuser
  • 1,885
  • 5
  • 26
  • 42
3
votes
3 answers

Why do I need to put @NamedQuery on Entity class?

I am currently learning about JPA NamedQueries and tried to use it in GuestServlet: Query getGuests = em.createNamedQuery("myq"); @SuppressWarnings("unchecked") List guests = getGuests.getResultList(); It works when I put the @NamedQuery…
3
votes
2 answers

Named Query to return a List

Hello I am using dropwizard for my application. The resource class @Path("/people") @Produces(MediaType.APPLICATION_JSON) public class PeopleResource{ private PersonDAO pdao; public PeopleResource(PersonDAO pdao) { this.pdao =…
user_mda
  • 18,148
  • 27
  • 82
  • 145