jpql

JPQL and date comparison (constraint in the query)

前提是你 提交于 2019-12-11 02:22:31
问题 My Application model object contains a date field (time stamp): @Entity @Table(name = "MYTABLE") public class Application { private Date timeStamp; ... } I'm trying to construct a JPQL query that would select all applications that were changed today (i.e. their time stamp was changed anytime today). What is the best way to do this? 回答1: There is no perfect way with standard JPQL, JPQL doesn't provide Date arithmetic functions. But your provider might provide extensions (e.g. Hibernate and

JPQL Native Query using SUM and COUNT

ⅰ亾dé卋堺 提交于 2019-12-11 01:25:12
问题 I am trying to run the following code: public BigDecimal valuate(String searchTerms, String categoryPath) { Query query = em.createNativeQuery("SELECT SUM(maxBidAmount) / COUNT(maxBidAmount) FROM Item WHERE MATCH(title) AGAINST(':searchTerms') AND categoryPath=':categoryPath'", Double.class); query.setParameter("searchTerms", searchTerms); query.setParameter("categoryPath", categoryPath); double value = (double) query.getSingleResult(); return new BigDecimal(value); } When I do so, I get the

Sorting a list of JPQL Entities

大城市里の小女人 提交于 2019-12-10 19:52:53
问题 I've searched long and hard for an answer, but I haven't had any luck so far. I'm trying to retrieve and sort a list of objects via a JPQL query, but since the query itself uses a lot of joins between different tables, it's really difficult. Basically, we have an entity "Person" with the fields String name List<Telephone> phones List<Email> emails List<Address> addresses "Telephone", "Email", and "Address" are all separate Entities, each containing its own data, like a String field "number"

How to apply regular expression in JPQL?

一世执手 提交于 2019-12-10 18:40:21
问题 I'm using JPA (Hibernate) as the persistence layer. I need to add a WHERE clause based on a regular expression, such some pattern are SELECT * FROM TableName where REGEXP_LIKE(ColumnName, 'Pattern'). What I get from the result is the list of string but I need to get mapped entities from the DB as an object not a string. From my knowledge JPQL can return the result as an object but JPQL doesn't seem to support regular expressions, as it's a propietary extension from Oracle. How can I apply

JPQL/HQL and JPA/Hibernate: boolean expression in select constructor expression not working (unexpected AST node: AND, NPE, HqlSqlWalker.setAlias)?

二次信任 提交于 2019-12-10 18:03:49
问题 I have a JPQL statement to return a schedule of sports games: SELECT NEW com.kawoolutions.bbstats.view.ScheduleGameLine( ga.id AS gid , ga.scheduledTipoff AS scheduledtipoff ... , sch.finalScore AS homefinalscore , sca.finalScore AS awayfinalscore , sch.finalScore IS NOT NULL AND sca.finalScore IS NOT NULL AS hasfinalscore ) I want the last expression (boolean) to evaluate to a boolean to indicate whether a game's final score has been completely reported or not (two entities of type Score,

JPQL we can't CONCAT(String, Integer) EclipseLink?

笑着哭i 提交于 2019-12-10 17:44:04
问题 In a JPQL query I tried to concatenate a string with a integer, using CONCAT JPQL function, in a select clause, for example: SELECT CONCAT(c.idClient, ' ', c.name) FROM Clients c; But the result is not a readable String. Can we only use String in CONCAT function? Thanks in advance. 回答1: CONCAT is meant for Strings, the result of calling it with a number would most likely depend on your database. You could try converting the id to a char first, you could use the FUNC function in EclipseLink to

JPQL query for searching if a word/string is consisted in one of entity's fields

你说的曾经没有我的故事 提交于 2019-12-10 17:23:54
问题 Basicaly, its similar like looking if certain word exists in sentence. There is entity Post: public class Post implements Serializable { @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "post_id", unique = true, nullable = false) private Integer id; @Column(name = "post_title", length=300, unique = false, nullable = false) private String title; @Column(name = "post_date", unique = false, nullable = false) private Date date; ...} I am trying to implement JPQL query that will search for

FETCH JOIN maximum depth?

谁都会走 提交于 2019-12-10 15:45:20
问题 W was trying to fetch join over three levels: JOIN FETCH entity1.collection1.collection2 // two OneToMany relations but got: org.hibernate.HibernateException: Errors in named queries: [...] Is it because it was too deep, or because a collection of collections cannot be fetched this way? My max fetch depth is 3, if this is relevant. I can, at the same time, do a triple JOIN FETCH starting from the other side: JOIN FETCH entity3.entity2.entity1 // two ManyToOne relations Somehow I cannot find

Casting Integer to String in JPQL

左心房为你撑大大i 提交于 2019-12-10 14:15:20
问题 I want to have a JPQL query that may look like: entityManager.createQuery("Select a.* from A a WHERE CAST(a.num AS TEXT) LIKE '%345%' ", A.class); where a.num is an integer. I want to cast this to String to use the LIKE criteria. However above casting doesnt work in JPQL. Any idea about how can I implement this? 回答1: Could you be more specific, what your problem is? Do you have some kind of error or it the result of the query is just wrong? Because this code works fine for me: session

JAVA: NamedQuery String problem

僤鯓⒐⒋嵵緔 提交于 2019-12-10 13:18:09
问题 Hello guys I am having some problems with exact matches while doing a NamedQuery. I am currently using something like this: @NamedQuery(name = MyClass.GET_ENTRY_BY_NAME, query = "select e from Entry e where e.name =:"+ Entry.NAME ) ... Query query = em.createNamedQuery(MyClass.GET_ENTRY_BY_NAME); query.setParameter(Entry.NAME, myEntry.getName()); It works for most cases, however I noticed that in case the user pass the file name with an space at the end, the namedQuery ignores that character.