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
10
votes
1 answer

JPQL query with WHERE on nested fields

I have a java entity class UserBean with a list of events: @OneToMany private List events; EventBean has Date variable: @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date eventDate; Now in UserBean I want to create a…
user473453
  • 894
  • 2
  • 11
  • 23
8
votes
2 answers

JPA: How to convert LocalDateTime to LocalDate

How could I use @NamedQuery to get a coloumn as LocalDate type which is defined LocalDateTime type. How can i do it?
skip
  • 12,193
  • 32
  • 113
  • 153
8
votes
4 answers

Named query with input parameter

I am learning JPA with Hibernate, using maven as well. My problem is How can I use input parameters with UPDATE and SET clause in named query ? @NamedQuery(name = "updateEmailAddress", query = "Update User u set u.email = :email where u.username =…
WCM
  • 595
  • 3
  • 11
  • 27
8
votes
1 answer

fluent nhibernate named-query without using hbm file for the map

I am needing to create a named-query, and use it with one of the maps, that i currently have defined as a fluent map. is it possible to continue using the fluent map, and be able to create the named-query dynamically in code? or, is switching to a…
user57555
  • 183
  • 4
  • 17
8
votes
2 answers

JPA setParameter when dealing with "NOT IN (:param)"

I'm trying to set a parameter in my query, for example: select * from Cars where Cars.color NOT IN (:color_params) And when I'm adding the parameter in my JavaClass is like: ... query.setParameter("color_params", "RED,BLUE"); ... And this is not…
rafa.ferreira
  • 1,997
  • 7
  • 26
  • 41
7
votes
2 answers

Best indexing alternative to speed up querying my millions of data in PostgreSQL

I have a big table with more than 500 million rows. I'm trying to find the best indexing alternative to speed up the query time a bit. I suppose sorting according to timestamp slows the query time a lot. The table has 15 columns in it. My Table has…
7
votes
6 answers

java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY

I have a method in Dao Class that returns List back and I am using named Query public List getListByCustomer(Session session, int customerId, List strIds) { Query namedQuery =…
techGaurdian
  • 732
  • 1
  • 14
  • 35
7
votes
3 answers

JPA: select random row

This is my JPA ENTITY @Entity @NamedQueries({ @NamedQuery(name = "Question.randQuestion", query = "SELECT q FROM Question AS q ORDER BY RANDOM") }) @Table(name = "questions") public class Question implements Serializable { ..... } The…
user3168286
  • 81
  • 1
  • 1
  • 3
7
votes
0 answers

Reuse HQL named queries fragments

I'm using HQL named queries (which are defined in XML files) to query my database using Hibernate. Some of the queries are quite complex and I find myself copy-pasting substantial parts of one query to another, similar one. I was wondering if it's…
Stefan Haberl
  • 9,812
  • 7
  • 72
  • 81
7
votes
3 answers

JPQL with subquery to select max count

I'm trying to write a jpql query to select the user with the most comments. If two users have the same number of comments I want to select both. I tried this, something like this: SELECT c.user, COUNT(c.id) as commentCount FROM Comment…
Roland Schütz
  • 812
  • 2
  • 8
  • 21
6
votes
2 answers

JAVA: NamedQuery String problem

Hello guys I am having some problems with exact matches while doing a NamedQuery. I am currently using something like this: @NamedQuery(name = MyClass.GET_ENTRY_BY_NAME, query = "select e from Entry e where e.name =:"+ Entry.NAME ) ... Query query…
flavio_yama
  • 313
  • 1
  • 4
  • 10
6
votes
2 answers

Is it possible to move named queries of an entity to another class

I have an entity named Client, And it has some named queries and native named queries. What I want to do is, I want to move this named queries to another class. For that I would like to extend the Client entity by another class ClientQuery. And move…
arjuncc
  • 3,227
  • 5
  • 42
  • 77
5
votes
1 answer

How to load a Hibernate 'xxx.hbm.cfg' file in a JPA 2.0 project?

I have just started a Spring Roo application with Hibernate as a JPA2.0 provider. I am using the jars as…
Viriato
  • 2,981
  • 7
  • 40
  • 54
5
votes
1 answer

hibernate query returns only first character of string

When I run a query like this in oracle 10g using sqldeveloper, it runs fine. select 'Canada' as "country", emp.name as "name" from emp. Gives me the name and country. When I run it in hibernate as a named query, I get only 'C' instead of…
Victor
  • 16,609
  • 71
  • 229
  • 409
5
votes
1 answer

Run two @NamedNativeQuery query on same entity Class

I want to define two @NamedNativequery on entity class . When tying to define eclipse gives a error. Duplicate annotation of non-repeatable type @NamedNativeQuery. Only annotation types marked @Repeatable can be used multiple times at one …
1
2
3
34 35