named-query

NamedQuery: IllegalArgumentException (Query not found) after externalizing entities

风格不统一 提交于 2019-12-03 11:16:53
I have successfully used javax.persistence.NamedQuery in combination with JPA2. The named queries are defined at the top of the entity class files, and are used from Stateless EJBs (entity facade). Now I had to extract the entity class files into a separate Jar file (so we can use them from a Google Web Toolkit project). Obviously I still incude the jar, but now the facade bean does not find the query anymore: java.lang.IllegalArgumentException: NamedQuery of name: Store.findByExternalId not found. at org.eclipse.persistence.internal.jpa.EJBQueryImpl.getDatabaseQueryInternal(EJBQueryImpl.java

Hibernate errors in named queries

夙愿已清 提交于 2019-12-02 12:59:34
问题 I am trying to pull information from a table where the current date is between the first and last day of any given month. I am getting a runtime error "Errors in named queries: Department.byDate" I am providing you with what code I think could be causing the problem, if any additional code is needed please let me know in a comment. My named query which looks like this: @NamedQuery(name="Department.byDate", query="select * from department where date >= :first AND date <= :last") I am using

How to handle null value of number type in JPA named query

江枫思渺然 提交于 2019-12-02 06:45:47
问题 I want to pass two parameters to namedquery. One is number type and the other is String type. They both could be null. For instance, (id=null, username='joe') and (id=1, username='joe') are two different results. In namedQuery, the syntax is "u.id is null" if id is null, but "u.id = :id" if id is not null. My question is how to dynamically handle the id filed in namedQuery? Please check my sample code: 1.User.java @NamedQueries({ @NamedQuery(name = "getUser", query = "select u from User u" +

Hibernate errors in named queries

谁都会走 提交于 2019-12-02 04:12:17
I am trying to pull information from a table where the current date is between the first and last day of any given month. I am getting a runtime error "Errors in named queries: Department.byDate" I am providing you with what code I think could be causing the problem, if any additional code is needed please let me know in a comment. My named query which looks like this: @NamedQuery(name="Department.byDate", query="select * from department where date >= :first AND date <= :last") I am using this named query in my DAO in a method which looks like this: public List<Department> getRecords(Date

Hibernate — Criteria vs named query

僤鯓⒐⒋嵵緔 提交于 2019-12-02 03:59:09
问题 I'm trying to compare Hibernate Criteria to named queries for performance. i'm aware it all depends on the actual query itself and the last word is on how they profile in runtime. still, trying to sort out what goes into each. i tried to organize the Q in two parts & looking for verification/correction on both: PART-1 -- how Hibernate Criteria and named queries work basically: Criteria works on parameters. In runtime, the query doesn`t need parsing-- has several search and "present-in-form"

Using Hibernate HQL Named Queries in Grails?

微笑、不失礼 提交于 2019-12-01 05:59:14
问题 Is there a way to use Hibernate Named Queries in Grails, using HQL? I've been reading about them in the Harnessing Hibernate book, and wondered if there was a way to use them in Grails. Named queries are included, along with the class mappings, in a <class-name>.hbm.xml mapping files like so: <query name="com.oreilly.hh.tracksNoLongerThan"> <![CDATA[ from Track as track where track.playTime <= :length ]> </query> Now I'm certain that an <class-name>.hbm.xml hibernate mapping file can be

Named Query with like in where clause

天涯浪子 提交于 2019-11-30 04:30:51
Is it possible to have a like in a where clause in a named query? I am trying to do the following but am getting exceptions @NamedQuery(name = "Place.getPlaceForCityAndCountryName", query = "SELECT p FROM Place p WHERE " + "lower(p.city) like :city and " + "lower(p.countryName) like :countryName"); I tried adding % as you would do in normal SQL but get exceptions compiling. Any pointers greatly appreciated! Thanks You can't have the % in the NamedQuery , but you can have it in the value you assign the parameter. As in: String city = "needle"; query.setParamter("city", "%" + city + "%"); You

Named Query with like in where clause

戏子无情 提交于 2019-11-29 01:46:59
问题 Is it possible to have a like in a where clause in a named query? I am trying to do the following but am getting exceptions @NamedQuery(name = "Place.getPlaceForCityAndCountryName", query = "SELECT p FROM Place p WHERE " + "lower(p.city) like :city and " + "lower(p.countryName) like :countryName"); I tried adding % as you would do in normal SQL but get exceptions compiling. Any pointers greatly appreciated! Thanks 回答1: You can't have the % in the NamedQuery , but you can have it in the value

JPA Named Queries vs Criteria API?

心不动则不痛 提交于 2019-11-29 00:38:30
问题 Is there a heuristic/best practice/ruleset for a decision between the Criteria API and NamedQuery ? My thoughts so far : Named queries are generally more readable. Criteria queries are more flexible. Both are precompiled. I tend to rely on using named queries as long as possible, then changing to criteria. But maybe the urge to "flexify" the query by using the criteria API is a hint to suboptimal design (i.e. separation of concerns)? Thank you 回答1: Named queries are more optimal (they are

Optional parameters with named query in Hibernate?

℡╲_俬逩灬. 提交于 2019-11-27 20:26:45
Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate ? I'm using a native SQL query, but the question is probably applicable to named HQL queries as well. I'm pretty sure the answer to this is 'no', but I haven't found the definitive answer in the documentation yet. Pascal Thivent AFAIK, there is no such thing so you'll have to write a dynamic query for this. Maybe have a look at this previous answer showing how to do this in HQL (that you can transpose to SQL) and