jpql

JPQL to query entity connected to another by @OneToMany

Has: class Container { @Id @Column(name="id") protected long id; @OneToMany @JoinColumn(name="container_id", nullable=false) protected Collection<Content> contents = new ArrayList<Content>(); } and class Content { @Id @Column(name="id") protected long id; @Column(name="link_id") protec...

Database design for Group Notification System

I am trying to create a group notification system. If I am in a group, then anyone who comment on the group's wall, a notification will send out to every group member. Here is my database design: I have two tables: Notification and NotificationRead. NotificationRead +userId (String) +lastRead (int) - default is 0 Notification ... +time...

What to use: JPQL or Criteria API?

My Java application is using JPA for object persistence. The business domain is very simple (just three classes are persistent, with 3-5 properties in each). Queries are simple as well. The question is which approach I should use: JPQL or Criteria API? ...

JPA query exception

Hello ! I have a query builded with EntityManager: Query q = em .createQuery("SELECT * FROM :table WHERE username = :username AND password = MD5(:password)") .setParameter("table", User.class.getName()) .setParameter("username", txtLogin.getText()) .setParameter("password", passPassword.getPassword()) ; User user = (Us...

How to implement NamedQuery based finder in Spring Roo ?

Hi, I can't find information about how to use standard JPQL based queries with Spring Roo project. I'm not sure if dynamic finders will be sufficient for complex queries. Is there any way to use @NamedQueries in Spring Roo project without breaking the concept of absence of DAO layer ? ...

How to set collection items for in-clause in jpql?

Is there a possiblity in JPA 2.0 to set a collection for in-clause in jpql-query? (I'm using EclipseLink) The next example fails: TypedQuery<Person> q = em.createQuery("select p from Person p where p.name in (?1)", Person.class); List<String> names = Arrays.asList(new String[] { "Bill Gates", "Steve Jobs" }); // THIS FAILS q.setParame...

Positional Parameter with IN clause in JPA

I'm trying to evaluate the following JPQL query: select err from Error err where err.errType = ? and err.msg in (?) The err.msg is a relationship to an Object derived from a class called CSMessage. So I do something like this: ...fetch my CSMessage from the DB. This part actually works... List<CSMessage> msgList = new ArrayList<CSM...

EclipseLink: don't fetch some fields by default

Let's say we have an entity @Entity public class Person { @Id int id; @Basic String name; @Basic String remark; } Let's say "remark" field is filled with big texts, but rarely used. So it would be good if when you run jpql: SELECT p FROM Person p, EclipseLink just executes sql select id, name from person And than when you...

JPQL: How to include Forward Slash in Query String?

How do you properly escape a '/' forward slash in a JPQL query string? If I do this: LOCATE('/', REVERSE( ... I get: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query However, if I do this: LOCATE('\\', REVERSE( ... Everything is fine. So, how do I include the forward...

Any tools for testing ad hoc JPQL queries outside of an application?

I'm working on a project which uses JPA for persistence, and I'm trying to find the cleanest and most efficient means for testing JPQL queries. I am more accustomed to the Hibernate world... in which you can test HQL on an ad hoc basis outside the application, using Hibernate Tools and its Hibernate Console. I believe that tool also su...

JPQL exclude subclasses in a query

If I have a class Apple that extends Fruit, how do I write a JPQL query to return all objects that are strictly Fruits and not Apples? ...

JPQL maxResults on collection objs

Hello I have the following situation: a class Event that has a collection of Participant objects, but the class Participant don't have any reference to event. So, I need to get the first 5 most recent participants of a given event, just could not figure out how to this. I know that after get the query done I just need to limit the resu...

JPA 2 Query Returning Incomplete Results

The following query is only matching the first value found in the select subquery, even though there are match for all values SELECT p FROM Profile p WHERE p.id IN (SELECT u.group FROM User u WHERE u.id = ?1) The subquery returns a comma separated list like: 1,2,3. The query should return matches for all three subquery select results. A...

JPA Typed Search Queries

I have a rather big model Applicant: public class Applicant{ private Long id private String name; ... ... } To populate a selection list, I need a list of (id, name) tuples and I use this search query: public List getNames() { Query query = em.createQuery("select a.id, a.name from Applicant a"); return query.getResultL...

JPQL/HQL count(collection) in where clause

hey everybody, I'm struggling to find the solution for the following problem: I want to get all the picture albums which have at least one picture. In SQL i would to something like: SELECT pa.id FROM album pa JOIN picture pi ON pa.id = pi.album_id GROUP BY pa.id HAVING count(pi.id) > 0 But I don't know how to do this in JPQL... Obv...

Trouble converting SQL Query into JPQL (Eclipselink)

Hey guys, I have the following query and for the life of me I can't seem to translate it into JPQL. The working SQL is: select * from TB_PRINT_DETAIL y inner join (select JOB_ID,max(COPY_NUM) MAX_COPY_NUM from TB_PRINT_DETAIL group by JOB_ID ) x on y.JOB_ID = x.JOB_ID and y.COPY_NUM = x.MAX_COPY_NUM My feeble attempt at translati...

JPA QL - "winning bids of a user"

Hi, I have a simple app with User, Bid, and Auction, the relationships are clear I hope. Now I want to implement getWinningAuctionsOfuser( User u ), which would return the auctions which the given user is currently winning. I know how I would do this in SQL, but I don't have much experience with JP-QL. What's the best approach? Curr...