criteria

JPA CriteriaBuilder how to create join + like query

こ雲淡風輕ζ 提交于 2019-12-11 05:16:58
问题 I have a SQL query: SELECT s.*, p.name, p.code FROM `stock` s LEFT JOIN product p ON s.product_id = p.id WHERE p.name LIKE "%q%" And I need to create the query using criteriabuilder I started so: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Long> cq = cb.createQuery(Long.class); Root<Stock> stock = cq.from(Stock.class); Path<String> path = stock.get(filter.getKey());//i have error here String likeValue = wildCard + value + wildCard; Predicate filterCondition = cb.conjunction();

Translate SQL command to Nhibernate Linq using Criteria or QueryOver - Count results of ditinct selected columns

笑着哭i 提交于 2019-12-11 04:50:11
问题 I'm trying to translate the following SQL statement into Nhibernate query using Criteria or QueryOver but it's not working!! the SQL command is: select Count(*) from ( select distinct col1, col2, col3 from tableName where col1 like '%t%' or col4 like '%t%' ) As x It either counts the results were's no projection applied, or it gives me a run-time error regards using this query.SetProjection(Projections.Count(Projections.Distinct( Projections.ProjectionList() .Add(Projections.Property("col1"))

Why do subqueries with nested properties in EclipseLink always produce an unnecessary/redundant/duplicate/superfluous join?

旧时模样 提交于 2019-12-11 03:52:03
问题 I wanted to generate the following SQL through EclipseLink (2.6.1) JPA criteria. SELECT zonecharge0_.charge AS col_0_0_ FROM projectdb.zone_charge zonecharge0_ WHERE ( EXISTS ( SELECT country1_.country_id FROM projectdb.country country1_ WHERE country1_.country_id=? and zonecharge0_.zone_id=country1_.zone_id ) ) AND ( zonecharge0_.weight_id IN ( SELECT MAX(weight2_.weight_id) FROM projectdb.weight weight2_ WHERE weight2_.weight BETWEEN 0 AND 60 ) ) Running both of the following criteria and

LINQ join with filter criteria

自闭症网瘾萝莉.ら 提交于 2019-12-11 02:18:13
问题 How is something like this done in linq? It has filter criteria on the JOIN. This is taken from this question: SQL Filter criteria in join criteria or where clause which is more efficient select salesman.salesmanid, max(sales.quantity) from salesman inner join sales on salesman.salesmanid =sales.salesmanid and sales.salesdate < salesman.promotiondate group by salesman.salesmanid Thanks 回答1: You can't join on anything other than equals , but that's probably not what you want here anyway. I

Getting DATEPART in HQL or Criteria?

一世执手 提交于 2019-12-11 02:07:26
问题 How can i get DATEPART of a time using HQL or Criteria ? I have googled it up and get some tips, but wasn't enough. If there is someone who has experienced it before, please let us know. Thanks in advance 回答1: Take a look at this post about using sql functions in nhibernate from ayende. EDIT I have had success with something like this in the configuration file : <property name="query.substitutions"> true 1, false 0, yes 'Y', no 'N',getdate=getdate </property> notice the getdate=getdate, not

hibernate criteria query for timestamp

旧街凉风 提交于 2019-12-11 01:51:43
问题 I have one table which has a column submitted_date(time-stamp without timezone). I need to list all records in the table having a particular date as submitted date. But do not consider the time in database. I retrieve the records by using criteria query and hibernate. How to ignore the time here? Actually I pass a date from client side and has to retrieve the records that have the same date as submitted_date. But no need to consider the time. else if(extjsFilter.getField().equals(

hibernate criteria query select for update order by

≯℡__Kan透↙ 提交于 2019-12-11 01:38:36
问题 I have the following code that uses Hibernate Criteria API. List<?> results = getCurrentSession() .createCriteria(PersonEvent.class) .add(Restrictions.eq(STATUS, EventStatus.NEW)) .addOrder( Order.asc("sequence") ) .setLockMode(LockMode.PESSIMISTIC_WRITE) .setMaxResults(maxResults).list(); It generates the following sql select * from ( /* criteria query */ select this_.SEQUENCE as SEQUENCE0_0_, this_1_.CREATED_UTC as CREATED3_0_0_, this_1_.UPDATED_UTC as UPDATED5_0_0_, this_1_.STATUS as

How to get Count in Hibernate 5 CriteriaBuilder with criteria condition

拟墨画扇 提交于 2019-12-11 01:13:42
问题 When I checked below code I got the count of all record. not condition wise. CriteriaBuilder builder = getCurrentSession().getCriteriaBuilder(); CriteriaQuery<Long> countQuery = builder.createQuery(Long.class); countQuery.select(builder.count(countQuery.from(ViewEmployees.class))); Long q1 = getCurrentSession().createQuery(countQuery).getSingleResult(); I want to get the count with criteria condition. like this code CriteriaQuery<ViewEmployees> query = builder.createQuery(ViewEmployees.class)

Database query j2me including criterias

a 夏天 提交于 2019-12-11 00:10:36
问题 I am creating an application with J2ME. for connecting with database i am using RecordStore. so to get a record i need to write as follow: public boolean SearchRecord(String Rec, int pos ) { String [] data = getRecordData(); Rec = Rec.substring(0,pos); for ( int i = 0 ; i < data.length ; i++ ) { data[i] = data[i].substring(0, pos ); if ( Rec.toString().trim().equals(data[i].toString().trim()) ) { data = null; // System.gc(); return true; } } data = null; // System.gc(); return false; } This

Hibernate children count criteria

只谈情不闲聊 提交于 2019-12-10 22:58:01
问题 I have parent/children relationship: newsItem 1-* comment. How can I select a list of newsItems and also count of comments for each newsItem using one Criteria query? I want to do something like this: select news_item.*, count(comment.id) from news_item left join comment on comment.news_item_id = news_item.id group by news_item.id The result should be the List of Object[2] { newsItem, int }. Could this be accomplished with Criteria queries? Thanks! 回答1: Well, I've found a solution. Hope it