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

How to call a SQL function like "HOUR()" in a @NamedQuery in Java Persistence

I need to know how to call a SQL function like HOUR() in a @NamedQuery in Java Persistence. To make it simpler, In a table that has a starttime (TIMESTAMP) column, I need to get the rows that have the startime falling between CURRENT_TIMESTAMP and…
3
votes
1 answer

java.lang.IllegalArgumentException: You have attempted to set a parameter value using a name of string that does not exist in the query string

I have the following named query: @NamedQuery( name = "Userdetails.findByUsername", query = "SELECT u FROM Userdetails u WHERE u.username = :username" ) When I try to execute it as follows: getEntityManager() …
user2061913
  • 910
  • 2
  • 14
  • 34
3
votes
1 answer

JPA - insert into select - copy large amount of records

I would like to copy records with diffrent key values. what is the best way to do so ? In plain sql I would do: insert into tableX values (x1,x2,x3,x4,x5) select 2,T1.x2,T1.x3,T1.x4,T1.x5 from tableX T1 (x1 is my primary key). I tried writing this…
user2046810
  • 393
  • 1
  • 8
  • 21
3
votes
2 answers

How to return a Map using named query?

I am using named query for returning List. But now i have a requirement that i have to return a Map so that i can filter the duplicates using the key.. I have a named query to return a List for product names,
Lucky
  • 16,787
  • 19
  • 117
  • 151
3
votes
2 answers

"Errors in named queries: User.findByUserNameAndPassword "- Not able to solve

This is the first question I have posted here, so apologies in advance if I have violated any conventions or etiquette. I can't seem to get rid of the following exception: Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default]…
3
votes
2 answers

Checking if ID contained in a list in JPA

I have an entity which contains a list of other entities. For example it could be Person with a list of Address entities. The addresses are not specific to one person. (it is actually a many to many relationship with a join table in the middle in…
RNJ
  • 15,272
  • 18
  • 86
  • 131
3
votes
1 answer

Named query when property is an object?

I would like to make this query in JPA: SELECT * FROM `happyDB`.`users` U WHERE U.party_as_user =1 AND U.party_party_id =2 This is working fine, but my problem is that I have Party only as an object, not as an id and I can't make it work. In the…
Sami
  • 2,311
  • 13
  • 46
  • 80
2
votes
2 answers

Hibernate named queries and startup performances

We are starting a new projet using JPA/Hibernate. Someone in the team is refusing to use named queries saying that he had performance issues with those before. According to him, the named queries are not only parsed at startup but they also are…
Jan
  • 213
  • 1
  • 3
  • 11
2
votes
0 answers

nhibernate named query join single record

This is what i have: class Unit { public Position ManagerPosition; }
Chill
  • 21
  • 2
2
votes
1 answer

Calling Stored Procedure using NHibernate as a Named Query with Input Parameters

Problem Description: I am trying to execute a stored procedure with an input parameter. The stored procedure executes correctly when run from MSSQL 2008 SQL Studio. However I get an error while running it as a named query using NHibernate. I get the…
2
votes
1 answer

Named Queries Pros and Cons

Is there any significant advantage of having queries as NamedQueries over the Entities? If not we could have it in the DAO itself. Kindly throw some ideas in this regard.
Sripaul
  • 2,227
  • 9
  • 36
  • 60
2
votes
0 answers

JPA NamedQuery for OneToMany Relation

I am trying to create a named-query in my orm.xml but I am not sure how it works with the collection. I have created a query in postgresql which gives me the correct output. But I am not able to translate it to my orm.xml. The…
deanavenger
  • 582
  • 1
  • 7
  • 24
2
votes
0 answers

java.lang.IllegalArgumentException: Parameter does not exist as a named parameter

try { LOG.debug("Entering readDb at {}", System.currentTimeMillis()); Session session = transactionManager.getSessionFactory().getCurrentSession(); Query query = null; ReturnTrackerEntity rtEntity =…
2
votes
0 answers

JPA Named Query for sql 'is not true'

I am using JPA with hibernate and named query and I need have a named query like this: findInstancesByCol1NotEquals(Boolean.TRUE) This generates sql like this: select * from instance where col1 <> true; But I have entries with null values that did…
tviana
  • 407
  • 4
  • 20
2
votes
1 answer

Same @NamedQueries in two different entities gives warning

I've same @NamedQueries in two entities as like below: @Table(name = "STUDENT_TABLE") @NamedQueries({ @NamedQuery(name = "getStudentById", query = "SELECT s FROM Student s where s.stdId=:stdId"), @NamedQuery(name = "getStudentByName", query =…
sivabalaji
  • 43
  • 1
  • 8