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

JPQL IN clause: Java-Arrays (or Lists, Sets...)?

I would like to load all objects that have a textual tag set to any of a small but arbitrary number of values from our database. The logical way to go about this in SQL would be to build an "IN" clause. JPQL allows for IN, but it seems to require me…
Bernd Haug
  • 2,157
  • 3
  • 17
  • 21
34
votes
5 answers

Optional parameters with named query in Hibernate?

Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate? I'm using a native SQL query, but the question is probably…
Ickster
  • 2,167
  • 4
  • 22
  • 43
34
votes
5 answers

Named Query with like in where clause

Is it possible to have a like in a where clause in a named query? I am trying to do the following but am getting exceptions @NamedQuery(name = "Place.getPlaceForCityAndCountryName", query = "SELECT p FROM Place p WHERE " + "lower(p.city)…
RNJ
  • 15,272
  • 18
  • 86
  • 131
33
votes
4 answers

JPA count NamedQuery

how to get count with a namedquery, without getting all the list (it would increase performance I think). This is the named query that doesn't work: @NamedQuery(name = "Charakteristika.findAllCount", query = "SELECT COUNT(c) FROM Charakteristika…
Minutis
  • 1,193
  • 1
  • 17
  • 47
30
votes
1 answer

Return value of JPA query when no matches found

I'm using Spring JPA named querys in my repository. My problem is, that I can't find anywhere information what would be returned value for a query that wouldn't match any results. I assume it'll be null for findOne() but I have no idea what would it…
xenteros
  • 15,586
  • 12
  • 56
  • 91
29
votes
5 answers

JPA Named Queries vs Criteria API?

Is there a heuristic/best practice/ruleset for a decision between the Criteria API and NamedQuery? My thoughts so far : Named queries are generally more readable. Criteria queries are more flexible. Both are precompiled. I tend to rely on using…
kostja
  • 60,521
  • 48
  • 179
  • 224
20
votes
4 answers

How to call Named Query

I wrote a named query in the entity class Voter NamedQuery(name = "Voter.findvoter", query = "SELECT count(*) FROM Voter v WHERE v.voterID = :voterID" and where v.password= : password), I want to call this named query and I also need to set voterID…
sandeep
  • 227
  • 2
  • 6
  • 9
20
votes
4 answers

define named query in orm.xml with jpa and hibernate

I'm trying to put my named queries in my orm.xml (put in META-INF with persistence.xml) but my orm.xml seems to be ignored by hibernate/jpa. When I try to create my named query with em.createNamedQuery("myQuery"), it returns that it can't find this…
Jerome Cance
  • 8,103
  • 12
  • 53
  • 106
16
votes
1 answer

Executing Named Queries in Athena

We want to execute a parameterized query in Athena using the javascript sdk by aws. Seems Athena's named query may be the way to do, but the documentation seems very cryptic to understand how to go about doing this. It would be great if someone can…
14
votes
1 answer

NamedQuery: IllegalArgumentException (Query not found) after externalizing entities

I have successfully used javax.persistence.NamedQuery in combination with JPA2. The named queries are defined at the top of the entity class files, and are used from Stateless EJBs (entity facade). Now I had to extract the entity class files into a…
Hank
  • 4,597
  • 5
  • 42
  • 84
14
votes
1 answer

Are Hibernate Named Queries precompiled in the true sense?

Pre-compiled queries are compiled and cached in advance by DB vendor (like oracle,sql server etc) so that they can be faster for successive calls like prepared statement. In Hibernate Named queries are said to be pre-compiled at web server start up.…
M Sach
  • 33,416
  • 76
  • 221
  • 314
11
votes
1 answer

@NamedNativeQuery with @SqlResultSetMapping for non-entity

I have been using this post as an example. I have a complex join query (simplified here). It returns a subset of values from two tables (and a derived column using CASE). I don't think I need to use an entity annotation because the object returned…
Micho Rizo
  • 1,000
  • 3
  • 12
  • 27
11
votes
3 answers

Can I use SQL's IN(...) statement for a namedQuery?

How can I use IN at my namedQuery? @NamedQueries( { @NamedQuery(name = "GetAvailableProducts", query = new StringBuilder("").append("SELECT p FROM Product p WHERE p.type= :type AND (p.available IN ('I want to define changeable size of an…
kamaci
  • 72,915
  • 69
  • 228
  • 366
11
votes
3 answers

Hibernate update with EntityManager

I am using Hibernate 4.1.7 and trying to update object, but theres no documentation how it should be done. Currently, I am doing this: Person person = personDao.getPersonById(1); person.setAge(23); person.setLastname("McName"); …
Timo
  • 141
  • 1
  • 2
  • 6
10
votes
1 answer

JPA named query match a list of tuples in IN clause

spring data jpa 1.4.3 with Oracle 11g. I have an entity like this: class LinkRecord { String value; int linkType; ... } I am using (value, linkType) as a composite index. For a given list of (v, t) tuples, we need to select all the records in…
pyy
  • 101
  • 1
  • 5
1
2 3
34 35