jpql

java.lang.ClassCastException with the same class object

不问归期 提交于 2019-12-02 07:36:05
问题 This piece of code irritates me, sometimes it working and some other times it doesn't ! The NamedQuery : (name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") public User findByLogin(String login) { Query query = em.createNamedQuery("User.findByLogin"); query.setParameter("login", login); try { return (User) query.getSingleResult(); } catch (javax.persistence.NoResultException ex) { return null; } } The error make me crazy ! Avertissement: EJB5184: A system

Does Eclipselink support queries containing regular expression?

萝らか妹 提交于 2019-12-02 06:32:36
问题 I've seen that DBMS like MySQL supports query containing regular expressions. Does Eclipselink support this? I have to retrieve entities having some String attribute matching some regular expression as SELECT X FROM Person X WHERE X.name <some keyword> (A-Z)* 回答1: MySQL uses REGEX or RLIKE for regular expression queries. JPQL does not support these operators, so you can use a native SQL query. In EclipseLink you could define your own ExpressionOperator for these, and use it in an Expression

java.lang.ClassCastException with the same class object

核能气质少年 提交于 2019-12-02 03:58:37
This piece of code irritates me, sometimes it working and some other times it doesn't ! The NamedQuery : (name = "User.findByLogin", query = "SELECT u FROM User u WHERE u.login = :login") public User findByLogin(String login) { Query query = em.createNamedQuery("User.findByLogin"); query.setParameter("login", login); try { return (User) query.getSingleResult(); } catch (javax.persistence.NoResultException ex) { return null; } } The error make me crazy ! Avertissement: EJB5184: A system exception occurred during an invocation on EJB UserFacade , method: public dz.admin.entity.User dz.admin

Set optional parameters in JPQL Query

一个人想着一个人 提交于 2019-12-02 03:02:57
问题 I got this list of coins that i want to filter with that 3 optional parameters(Currency, quantity and year) How can I set parameters in JPQL as optional? I dont want to do 9 "if else" for checking if its null I got the function filtradoMonedas (filterCoins) that filter the object Moneda(coin) using that 3 OPTIONAL parameters but its not working if there´s a null parameter. This just work well if dont set empty parameters, if cantidad or ano is "" returns exception of bad query. Just want it

How to skip @Param in @Query if is null or empty in Spring Data JPA

≡放荡痞女 提交于 2019-12-02 02:17:14
问题 @Query(value = "Select f from Documents f " + "RIGHT JOIN f.documentStatus ds " + "where f.billingAccount.accountId in :billingAccountIdList " + " and ds.statusCode in :paymentStatuses" + " and f.paymentDate < :paymentDate") List<FinancialDocumentEntity> getFinancialDocumentsOverdue(@Param("billingAccountIdList")List<String> billingAccountIdList, @Param("paymentStatuses") List<String> paymentStatuses, @Param("paymentDate") Date paymentDate); I have query like above. It is possible to skip

Set optional parameters in JPQL Query

时光怂恿深爱的人放手 提交于 2019-12-02 02:06:53
I got this list of coins that i want to filter with that 3 optional parameters(Currency, quantity and year) How can I set parameters in JPQL as optional? I dont want to do 9 "if else" for checking if its null I got the function filtradoMonedas (filterCoins) that filter the object Moneda(coin) using that 3 OPTIONAL parameters but its not working if there´s a null parameter. This just work well if dont set empty parameters, if cantidad or ano is "" returns exception of bad query. Just want it as an optional. Heres the method: public List<Moneda> filtradoMonedas(Divisa divisa, BigDecimal cantidad

Query using “CASE WHEN” statement in WHERE causes QuerySyntaxException: unexpected AST

泄露秘密 提交于 2019-12-02 01:01:20
I'm trying to make a query using Spring Data, but I cannot make it work: @Query(SELECT t FROM Thing t WHERE name LIKE :name AND CASE WHEN (:minVal <= 0) THEN TRUE ELSE (val <= :minVal) END AND CASE WHEN (:maxVal <= 0) THEN TRUE ELSE (val >= :maxVal) END) Page<Thing> getThings(@Param("name") String name, @Param("maxVal") int maxVal, @Param("minVal") minVal); StackTrace: Caused by: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: CASE near line 1, column 49 [SELECT t FROM Thing t WHERE name LIKE :name AND CASE WHEN (:minVal <= 0) THEN

How to work with alias in JPQL

[亡魂溺海] 提交于 2019-12-02 00:39:11
问题 I'm trying to get some values from a H2 db table. The query which does what I need is this: SELECT cast(creationDate as date) as DATE, SUM(paymentValue) as TOTAL,fxRate FROM payment group by DATE where "creationDate", "paymentValue", "fxRate" are columns of the table "payment". CreationDate is a timestamp so I have to get only the date from it. When I try to write it in Java @Query("SELECT cast(creationDate as date) as daydate , SUM(paymentValue) as value1, fxRate as value2 FROM payment " +

Does Eclipselink support queries containing regular expression?

若如初见. 提交于 2019-12-02 00:29:31
I've seen that DBMS like MySQL supports query containing regular expressions. Does Eclipselink support this? I have to retrieve entities having some String attribute matching some regular expression as SELECT X FROM Person X WHERE X.name <some keyword> (A-Z)* MySQL uses REGEX or RLIKE for regular expression queries. JPQL does not support these operators, so you can use a native SQL query. In EclipseLink you could define your own ExpressionOperator for these, and use it in an Expression query, but not currently with JPQL. JPQL does support calling database functions using FUNC, but these have

How to work with alias in JPQL

跟風遠走 提交于 2019-12-01 23:28:34
I'm trying to get some values from a H2 db table. The query which does what I need is this: SELECT cast(creationDate as date) as DATE, SUM(paymentValue) as TOTAL,fxRate FROM payment group by DATE where "creationDate", "paymentValue", "fxRate" are columns of the table "payment". CreationDate is a timestamp so I have to get only the date from it. When I try to write it in Java @Query("SELECT cast(creationDate as date) as daydate , SUM(paymentValue) as value1, fxRate as value2 FROM payment " + "group by cast(creationDate as date)") List<Payment> findPaymentValuePerDay (); I get the error [Ljava