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
4
votes
3 answers

Named queries with nHibernate

I am having a great deal of trouble getting named queries to work with nHibernate. My latest problem is getting the error message "could not execute query" with no additional information. Are there any complete examples I can download from somewhere…
Craig
  • 36,306
  • 34
  • 114
  • 197
4
votes
0 answers

JPA: How can I return a generic/type class from EntityManager?

How can I make Eclipse understand that I expect a type result from em.createQuery(...)? public class ReservationDaoImpl> extends JpaDaoImpl> implements ReservationDao { public…
du-it
  • 2,561
  • 8
  • 42
  • 80
4
votes
1 answer

Search keywords in database

I'm using Eclipselink and have a tricky problem regarding JPA NamedQueries. My database table contains a column which is from type VARCHAR and stores a comma separated list of keywords as one String. How can I create a NamedQuery in JPA to search…
LarsBauer
  • 1,539
  • 18
  • 23
4
votes
1 answer

spring-data Specification and joined subquery

I have the following Named query on my spring-data repository: @Query("FROM Pedido p JOIN FETCH p.status ps WHERE ps.status IN (?1) AND ps.id IN (SELECT MAX(ps2.id) FROM PedidoStatus ps2 GROUP BY ps2.pedido)") I'm trying to achieve the same result…
4
votes
3 answers

How do you decide in which entity classes to put JPA NamedQuery annotations?

Say I have a Customer - CustomerOrder one-to-many bi-directional relationship with the CustomerOrder holding the total value of each order. If I had a query to find the total value of all orders for a particular customer : select SUM(o.orderValue)…
blank
  • 17,852
  • 20
  • 105
  • 159
4
votes
2 answers

JPA @namedQuery with "IN" expression

Im having the following namedQuery: @NamedQuery(name = Department.getDepartmentsByIds, query = "SELECT tbl FROM Department tbl where tbl.id in (:departmentsIds)") I would like to pass the parameter: departmentsIds = "1,2,3" like…
Urbanleg
  • 6,252
  • 16
  • 76
  • 139
4
votes
0 answers

JPA Left Join and Count

I want to retrieve all Foo objects and for every Foo object the number of associated Bar objects (zero or more) from the database. I want to do this in one single query and I don't want to fetch lists of Bar objects just to get their sizes. The…
Jack
  • 1,881
  • 24
  • 29
4
votes
1 answer

NHibernate Fluent and named Queries

I am using Nhibernate with fluent. Now I want to call some Stored procedure and use named Queries. I created some xml: exec…
urpcor
  • 167
  • 2
  • 13
4
votes
3 answers

List of all NamedQueries in JPA

I want to get a list of all NamedQueries within my application and I also want to invoke them generically at runtime. Is there an option to get the list as well as some kind of meta-data (generally speaking some kind of Reflection)? Another Thread…
Subcomandante
  • 403
  • 1
  • 6
  • 14
4
votes
1 answer

NamedQuery with a CONCAT returns error

I am attempting to do a select query like the following: SELECT *, CONCAT(TNUSERDATE, ' - ', TNUSERTIME) AS datetime FROM TODONOTE WHERE TNTDKEY='TD00019148' ORDER BY datetime DESC; That query works; however, when I attempt to transfer it into…
Metal Wing
  • 525
  • 1
  • 11
  • 22
3
votes
1 answer

Hibernate named query DB or cache?

We are using Hibernate in our project. My question is regarding named queries. Can someone guide me on how named queries are handled by Hibernate. If Hibernate is configured to use level 1 cache will it also return results for the named query from…
java_buzz
  • 67
  • 1
  • 6
3
votes
1 answer

Using Hibernate HQL Named Queries in Grails?

Is there a way to use Hibernate Named Queries in Grails, using HQL? I've been reading about them in the Harnessing Hibernate book, and wondered if there was a way to use them in Grails. Named queries are included, along with the class mappings, in a…
leeand00
  • 25,510
  • 39
  • 140
  • 297
3
votes
1 answer

Named Queries Error in nhibernate

I have a named query in my nhibernate mapping file, and every time i run the code, it fails to create the Session with the message 'Errors in named queries', and no inner exception or anything else pointing to what's wrong with my named query. I'm…
sin cara
  • 123
  • 6
3
votes
1 answer

NHibernate pass Geography type to Named Query SetParameter()

I'm in the process of introducing NHibernate 3 into a data access layer for an ASP.NET MVC web application. Within the SQL Server 2008 R2 database, a geography datatype is used to store lat/long coordinates in a table that maps to an entity within…
Russ Cam
  • 124,184
  • 33
  • 204
  • 266
3
votes
1 answer

How do I create Named Queries in a Separate file

I need to keep the all the named queries in a separate file. For example @javax.persistence.NamedQueries({ @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e")}) public class AllNamedQueries { } Now that much in itself…
SQC
  • 591
  • 3
  • 9
  • 18