jpql

jpql order by subquery produces unexpected AST node exception

懵懂的女人 提交于 2019-12-01 21:10:50
I translated a working (postgre)sql query to jpql, but hibernate throws a org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node exception These are my core model classes: @Entity public class Piece { @Id @GeneratedValue public Long id; @ManyToOne public AUser user; public long index; ... } @Entity public class Vote { @Id @GeneratedValue public Long id; @ManyToOne public AUser receiver; ... } @Entity public class AUser { @Id @GeneratedValue public Long id; @OneToMany(mappedBy="receiver", cascade=CascadeType.ALL) public List<Vote> receivedVotes; ... } Here is my jpql query: String

Database independent string comparison with JPA

被刻印的时光 ゝ 提交于 2019-12-01 21:02:32
问题 I'm working with JPA (Hibernate as provider) and an underlying MySQL database. I have a table containing every name of streets in Germany. Every streetname has a unique number. For one task I have to find out the number of the name. To do this I wrote a JPQL-Query like the following "SELECT s FROM Strassencode s WHERE s.name = :name" Unfortunately there are streetnames in Germany which only differ in small and capital letters like "Am kleinen Feld" and "Am Kleinen Feld". Obviously one of them

JPA Date Arithmetic?

与世无争的帅哥 提交于 2019-12-01 18:24:36
问题 Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an entity with a java.util.Date field indicating when the row was created. Is it possible to perform a query using JPQL and include date arithmetic on that field? For example, can I perform a COUNT(*) of rows and then GROUP BY the month in that field? Can I perform other functions, such as only return the month or year from that field in a query? 回答1: HQL does have date expressions like second(...) , minute(...

JPA Date Arithmetic?

痞子三分冷 提交于 2019-12-01 17:59:05
Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an entity with a java.util.Date field indicating when the row was created. Is it possible to perform a query using JPQL and include date arithmetic on that field? For example, can I perform a COUNT(*) of rows and then GROUP BY the month in that field? Can I perform other functions, such as only return the month or year from that field in a query? HQL does have date expressions like second(...) , minute(...) , hour(...) , day(...) , month(...) , and year(...) but standard JPQL doesn't have such functions. 来源:

Building JPA Criteria API query - sorting by number of elements in collection

╄→尐↘猪︶ㄣ 提交于 2019-12-01 17:44:08
I am having problem with building a query with JPA Criteria API. Entities and significant properties: @Entity public class Post { @Id int id; @OneToMany (mappedBy = "post") Set<Comment> comments; //... } @Entity public class Comment { @Id int id; @ManyToOne Post post; //... } I need a query that will return all posts from db ordered by number of comments ( OneToMany in Post ). At first I thought this can be implemented with JPQL like: SELECT p FROM Post p ORDER BY SIZE(p.comments) DESC But function SIZE(...) can not be used to be ordered by it in JPQL . So, I found about JPA Criteria API , and

Java 8 Spring Data JPA Parameter binding

故事扮演 提交于 2019-12-01 13:55:20
问题 In my @Repository interface I created custom find method with JPQL @Query that contains parameter (addressType). from Address a where a.addressType = :addressType In the method I did not specify @Param("addressType") on the parameter. So I am getting java.lang.IllegalArgumentException: Name for parameter binding must not be null or empty! For named parameters you need to use @Param for query method parameters on Java versions < 8. Okay, this is pretty much clear, but I am using Java 8. So

Why do I get an invalid path when I try and construct a JPQL join query?

给你一囗甜甜゛ 提交于 2019-12-01 11:49:21
I’m using JPA 2.1, Hibernate 4.3.6.Final, and MySQL 5.5.37. How do I write a JPQL query that does a join? I’m trying below final String jpqlQuery = "SELECT m FROM Message m LEFT JOIN MessageReadDate mr " + " INNER JOIN m.group g " + " LEFT JOIN g.classroom c " + " LEFT JOIN c.ROSTER u WHERE " + " u.USER = :recipient AND " + " u.ENABLED = 1 AND " + " c.ENABLED = 1 AND " + " g.NAME = '' AND " + " m.author <> :author"; Query query = m_entityManager.createQuery(jpqlQuery); but getting the error “Path expected for join! … Invalid path: 'g.classroom'”. org.hibernate.hql.internal.ast.ErrorCounter -

Error in @Query , Repository

烂漫一生 提交于 2019-12-01 11:39:03
问题 Maybe error in @Query due to the fact that my entity have relation ? Which the Repository contain error. Error creating bean with name 'clickRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.lang.String com.qoobico.remindme.server.repository.ClickRepository.sent(java.lang.String,long)! Controller @Autowired private ClickService service; /* i.e. information about fullname_client, id

How can I do an UPDATE statement with JOIN in JPQL (Spring JPA Queries)?

走远了吗. 提交于 2019-12-01 11:36:31
问题 This is an extension of this question Update Statement with JOIN in SQL but I am trying to use Spring Data JPQL. I am trying to use Update along with JOIN in JPQL as follows @Modifying @Query("UPDATE TotalValue tv JOIN LineItems li WHERE li.totalValue.totalValueId=:totalValuedId SET tv.totalAmount =sum(li.itemTotalValue) ") void calculateTotalAmount(@Param("totalValuedId") Long totalValuedId); However, i get an error as follows org.hibernate.hql.internal.ast.QuerySyntaxException: expecting

How to do a complex LEFT JOIN condition in JPQL?

情到浓时终转凉″ 提交于 2019-12-01 11:13:32
I am using JPQL for the model queries from Play Framework. I wonder if JPQL supports "complex" ON condition for LEFT JOIN. In an example I have, there are 2 tables: 'App' - list of applications 'AggregationHistory' - the list of the aggregation records per application, per date. In the model, it has 'app' field representing many-to-one with 'App' (column name 'app_id' in the physical table) Suppose I want to calculate the list of all the apps that do not have a record for a specific date. In plain SQL, I get the result using the following query: SELECT a.* FROM app a LEFT JOIN