criteria

Hibernate, getting duplicate values

强颜欢笑 提交于 2019-12-19 03:12:08
问题 I am writing a very simple query, but I am getting duplicate values for some reason. Criteria cr = session.createCriteria(ProcessInstance.class, "p") .add(Restrictions.isNull("end")); @Cleanup ScrollableResults sr = cr.scroll(ScrollMode.FORWARD_ONLY); while (sr.next()) { pi = (ProcessInstance) sr.get(0); String id = pi.getId(); //Getting duplicate values } The pi.getId() returns duplicate values. ie: *9,9,10,10,11,11 etc* However, running this query directly in mysql SELECT * FROM JBPM

How to insert an “Optimizer hint” to Hibernate criteria api query

断了今生、忘了曾经 提交于 2019-12-18 13:25:26
问题 i have a hibernate query that is dynamically put together using the criteria api. it generates queries that are unbearably slow, if executed as-is. but i have noted they are about 1000% faster if I prepend /*+ FIRST_ROWS(10) */ to the query. how can i do this with the criteria api? i tried criteria.setComment(..), but this seems to be ignored. in the hibernate docs, 3.4.1.7. Query hints are mentioned, but it clearly states: "Note that these are not SQL query hints" the result of the query

NHIbernate OR Criteria Query

谁都会走 提交于 2019-12-18 13:12:36
问题 I have the following mapped classes Trade { ID, AccountFrom, AccountTo } Account {ID, Company} Company {ID} Now I cannot figure out a way select all trades where AccountFrom.Company.ID = X OR AccountTo.Company.ID = X I can get AND to work using the following: criteria.CreateCriteria("AccountFrom").CreateCriteria("Company").Add(Restrictions.Eq("ID", X); criteria.CreateCriteria("AccountTo").CreateCriteria("Company").Add(Restrictions.Eq("ID", X); But how can I transform this into an OR rather an

Refresh MS Access Form/Query Based On Combobox Value

浪尽此生 提交于 2019-12-18 09:22:57
问题 Pretty simple explanation. I have a table with 10 entries, 5 entries with the year 2010 and 5 entries with 2011 in a column. In the query I have, I use Like *2010 to filter out all entries equal 2010 and display onl those records. On my form, I have combobox being populated with each unique year (from a different table). So my combobox values are 2010 and 2011. Is it possible, when I select say 2011, I trim the right 4 characters and use as my Like criteria to refresh and requery the form,

Using the 'case…when…then…else…end' construct in the 'having' clause in JPA criteria query

时间秒杀一切 提交于 2019-12-18 07:03:18
问题 The following criteria query calculates the average of rating of different groups of products. CriteriaBuilder criteriaBuilder=entityManager.getCriteriaBuilder(); CriteriaQuery<Tuple>criteriaQuery=criteriaBuilder.createQuery(Tuple.class); Metamodel metamodel=entityManager.getMetamodel(); EntityType<Product>entityType=metamodel.entity(Product.class); Root<Product>root=criteriaQuery.from(entityType); SetJoin<Product, Rating> join = root.join(Product_.ratingSet, JoinType.LEFT); Expression<Number

NHibernate Left Outer Join

只愿长相守 提交于 2019-12-18 06:26:05
问题 I'm looking to create a Left outer join Nhibernate query with multiple on statements akin to this: SELECT * FROM [Database].[dbo].[Posts] p LEFT JOIN [Database].[dbo].[PostInteractions] i ON p.PostId = i.PostID_TargetPost And i.UserID_ActingUser = 202 I've been fooling around with the critera and aliases, but I haven't had any luck figuring out how do to this. Any suggestions? 回答1: I actually figured it out. You need to do a check for null .CreateCriteria("Interactions", "i", NHibernate

Subquery in select clause with JPA Criteria API

独自空忆成欢 提交于 2019-12-17 22:34:33
问题 I'm trying, as in title, to insert a subquery in select clause like in this simple SQL: SELECT id, name, (select count(*) from item) from item this is obviously only a mock query just to make my point. (The point would be to get the last invoice for each item returned by the query.) I've tried this: CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery<Tuple> c = cb.createTupleQuery(); Root<Item> item= c.from(Item.class); Subquery<Long> scount = c.subquery(Long.class); Root<Item>

VBA (Excel): Find Based on Multiple Search Criteria Without Looping

北城余情 提交于 2019-12-17 18:25:06
问题 I have a large data sheet that I want to search in VBA based on 3 sets of criteria . Each row entry can be assumed to be unique. The format of the sheet/data itself cannot be changed due to requirements. (I've seen several posts on related questions but haven't found a working solution for this yet.) At first I used the classic VBA find method in a loop: Set foundItem = itemRange.Find(What:=itemName, Lookin:=xlValues, lookat:=xlWhole, SearchOrder:=xlByRows) If Not foundItem Is Nothing Then

JPA - FindByExample

邮差的信 提交于 2019-12-17 17:45:12
问题 Does anyone have a good example for how to do a findByExample in JPA that will work within a generic DAO via reflection for any entity type? I know I can do it via my provider (Hibernate), but I don't want to break with neutrality... Seems like the criteria API might be the way to go....but I am not sure how to handle the reflection part of it. 回答1: Actually, Query By Example (QBE) has been considered for inclusion in the JPA 2.0 specification but is not included, even if major vendors

How to achieve “not in” by using Restrictions and criteria in Hibernate?

风格不统一 提交于 2019-12-17 17:39:34
问题 I have list of category. I need a list of category by excluding 2,3 row. Can we achieve through hibernate by using Criteria and Restriction? 回答1: Your question is somewhat unclear. Assuming "Category" is a root entity and "2,3" are ids (or values of some property of the category") you can exclude them using the following: Criteria criteria = ...; // obtain criteria from somewhere, like session.createCriteria() criteria.add( Restrictions.not( // replace "id" below with property name, depending