Questions tagged [jpql]

The Java Persistence Query Language (JPQL) is a platform-independent object-oriented query language defined as part of the Java Persistence API specification.

The Java Persistence query language (JPQL) is used to define searches against persistent entities independent of the mechanism used to store those entities. As such, JPQL is "portable", and not constrained to any particular data store. The Java Persistence query language is an extension of the Enterprise JavaBeans query language (EJB QL), adding operations such as bulk deletes and updates, join operations, aggregates, projections and subqueries.

3498 questions
57
votes
3 answers

How to use multiple JOIN FETCH in one JPQL query

I have below entities: public class Category { private Integer id; @OneToMany(mappedBy = "parent") private List topics; } public class Topic { private Integer id; @OneToMany(mappedBy = "parent") private List
Zaprogramowany
  • 623
  • 1
  • 7
  • 10
55
votes
5 answers

JPQL statement returning boolean value

Is it possible to write JPQL query like following: select count(*) > 0 from Scenario scen where scen.name = :name that would return true/false boolean values depending of whether entity filling criteria exists or not? I would like to use the query…
Piotr Sobczyk
  • 6,443
  • 7
  • 47
  • 70
54
votes
3 answers

How to write JPQL SELECT with embedded id?

I'm using Toplink essentials (JPA) + GlassFish v3 + NetBean 6.9 I have one table with composite primary key: table (machine) ---------------- |PK machineId | |PK workId | | | |______________| I created 2 entity classes one for…
Meow
  • 18,371
  • 52
  • 136
  • 180
54
votes
7 answers

How can I avoid the Warning "firstResult/maxResults specified with collection fetch; applying in memory!" when using Hibernate?

I'm getting a warning in the Server log "firstResult/maxResults specified with collection fetch; applying in memory!". However everything working fine. But I don't want this warning. My code is public employee find(int id) { return (employee)…
Gnik
  • 7,120
  • 20
  • 79
  • 129
52
votes
4 answers

JPA: Query that returns multiple entities

I'm writing a JPQL query that joins across three tables. In my resultlist I would like to get all three entities per matching row (hope that makes sense). Any ideas? Hibernate 3.x is my JPA provider.
Justin Kredible
  • 8,354
  • 15
  • 65
  • 91
52
votes
2 answers

JPQL SELECT between date statement

I would like to convert this SQL statement to a JPQL equivalent. SELECT * FROM events WHERE events_date BETWEEN '2011-01-01' AND '2011-03-31'; This correctly retrieves the information from the table events. In my Events entity @Column(name…
Mamadou
  • 577
  • 1
  • 4
  • 7
52
votes
9 answers

IntelliJ IDEA highlights @Entity class names with "Cannot resolve symbol" in JPQL

IntelliJ IDEA highlights persistent @Entity class names with "Cannot resolve symbol" in red in JPQL which is distracting and buries real issues. So, for example, I declare a query in my repository: private static final String READ_BY_CANDIDATE_KEY…
Simon Gibbs
  • 4,737
  • 6
  • 50
  • 80
51
votes
4 answers

JPQL limit query

How can I limit in a select query of JPQL named query? I need the limit to be done in the query level itself and not in the java layer!!! I am trying to use @NamedQueries(value = { @NamedQuery(name =…
user3115056
  • 1,266
  • 1
  • 10
  • 25
50
votes
6 answers

Is there a way to use constants inside Spring Data @Query annotation value?

I don't want to hardcode constant values, I would rather specify them through a reference variable. For example, rather then writing the next query: @Query(value = "SELECT u FROM UserModel u WHERE u.status = 1") ..I would like to extract the…
Roman
  • 64,384
  • 92
  • 238
  • 332
49
votes
5 answers

java.sql.SQLException: Fail to convert to internal representation

I'm trying execute following query: String query = "select entity, entity.id from Site entity"; List resultList = entityManager.createQuery(query).getResultList(); And take exception: [...] Caused by: java.sql.SQLException: Fail to convert to…
Ket
  • 491
  • 1
  • 4
  • 5
48
votes
4 answers

Are SQL injection attacks possible in JPA?

I'm building a Java Web Application using Java EE 6 and JSF-2.0, using the persistence API for all database operations. The back-end is MySQL, but I have used the EntityManager functions and Named Queries in EJB-QL for all operations. Are SQL…
Akshay
  • 1,606
  • 3
  • 17
  • 32
47
votes
3 answers

Doing an "IN" query with Hibernate

I have a list of IDs in a String, and want to use Hibernate to get the rows with these IDs. TrackedItem is a Hibernate/JPA entity (sorry if I'm getting the naming mixed up here). My code is: String idsText = "380, 382, 386"; ArrayList ids =…
Amy B
  • 17,874
  • 12
  • 64
  • 83
45
votes
1 answer

JPA: JOIN in JPQL

I thought I know how to use JOIN in JPQL but apparently not. Can anyone help me? select b.fname, b.lname from Users b JOIN Groups c where c.groupName = :groupName This give me Exception org.eclipse.persistence.exceptions.JPQLException Exception…
Thang Pham
  • 38,125
  • 75
  • 201
  • 285
41
votes
3 answers

org.hibernate.QueryException: JPA-style positional param was not an integral ordinal

I have the following JPQL request; @Query(value = "select req_t " + "from TransactionRelation tr " + "inner join tr.requestTransaction req_t " + "inner join req_t.transactionStateHistory req_t_h " + "inner join…
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710
40
votes
6 answers

JPA Native Query select and cast object

I have got an Object Admin which extends User. By default both Objects are in the table User_ of my Derby Database (included fields from Admin). Normally I'd select an User like this: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery
Menno
  • 12,175
  • 14
  • 56
  • 88