criteria

Grails named queries: find parents of child A and child B

落爺英雄遲暮 提交于 2020-01-07 06:42:12
问题 I have this: class Parent { String name static hasMany = [children: Child] } class Child { String name } And I want to find all the parents that have a child named "Tom" and another one named "Sam". id | parentName --------------- 1 | Peter 2 | Joe 3 | Ann id | childName --------------- 1 | Tom 2 | Sam idParent | idChild --------------- 1 | 1 2 | 2 3 | 1 3 | 2 In the example, it will be Ann. I've tried this: static namedQueries = { findParents{nameList -> children{ nameList.each{childName->

Wild card based on combo box not working

喜夏-厌秋 提交于 2020-01-06 13:58:47
问题 I've got a criteria within a query, can't quite get it to work: IIf([Forms]![Reports]![Office Filter]<>"View all offices",[Forms]![Reports]![Office Filter],"LIKE '*'") The purpose of the query is to check if an office is selected. If so, the criteria should be set to that office. If not, i.e. if "View all offices" is selected from the combobox on the Reports form, it should show all records. The query works fine if an office is selected, but returns no records if "View all offices" is

Unable to find how to code: If Cell Value Equals Any of the Values in a Range

别等时光非礼了梦想. 提交于 2020-01-06 01:33:07
问题 I have found the following code after a lot of research and it does a little of what I want it to do except I don't know how to specify the criteria to reference a range of cells instead of just one single criteria. I am also trying to copy the records and append them to the end of the rows of the matching records in Sheet1. This code only copies the records to Sheet3 so they aren't pasted with their corresponding rows in Sheet1 like I want. Sub copytosheet() Dim sRng As Range, cell As Range

关于solr7之后版本的动态域,不能使用中文作为拼接索引

可紊 提交于 2020-01-04 14:37:03
在做某电商搜索的时候,由于需要根据规格搜索。所以我们将商品的数据同步到solr,于是出现了动态域乱码问题 当时,需要对规格数据进行处理,我们将动态域的格式设置为item_spec_*当时的思路是:将规格的字段名作为索引,如某手机规格为:“item_spec_运行内存”. 结果变成了这个样子: 问题在于,无法使用汉字,可是不使用汉字,也没有合适的数据作为动态域. 所以想到一种方法.只要不是汉字,数据同步到solr就不会出现乱码情况.于是同步时,将其使用URLEncoder.encode()方法格式为UTF-8.将其转码,由于是JDK自带的.所以不需要加依赖.在某方法中具体代码如下: TbItemExample example=new TbItemExample(); TbItemExample.Criteria criteria = example.createCriteria(); criteria.andStatusEqualTo("2");//已审核 //查到了所有已审核的 List<TbItem> itemList = itemMapper.selectByExample(example); System.out.println("===商品列表==="); for(TbItem item:itemList){ //为了转化动态域,得到数据库中String类型的JSON对象

MongoDB Spring data comparison between fields

蹲街弑〆低调 提交于 2020-01-04 14:23:12
问题 I'm trying to simply do a comparison between my fields but it doesn't seems to work with spring data : query.addCriteria(Criteria.where("active").gt("limit")); Active and limit are 2 fields of my collection, and I wand to display all fields that exceed the limit. This limit is different for each item so I cannot do gt(200) for example... There is anyway to do that ? 回答1: You can fall back to your java driver and issue a $where query: DBObject obj = new BasicDBObject(); obj.put( "$where",

Hibernate Criteria: Projecting Count with group by clause

坚强是说给别人听的谎言 提交于 2020-01-04 02:39:33
问题 I want to execute the following SQL select count(*) as myCount from user group by name; I came up with the following criteria for the same DetachedCriteria.ForClass(typeof(UserDTO)) .setProjections(Projections.ProjectionList() .Add(Projections.rowCount(),"myCount") .Add(Projections.groupProperty("this.name")); I get the result back as pair of the count and name,How can I get just the count from this. 回答1: I don't think you can do it with Criteria, but it's easy with HQL. It's exactly the same

SpringDataJpa Specification接口用法

若如初见. 提交于 2020-01-03 19:58:43
原文链接:https://blog.csdn.net/bird_tp/article/details/83654789 Specification是springDateJpa中的一个接口,用于当jpa的一些基本CRUD操作的扩展,即spring jpa的复杂查询接口。Criteria 查询,是一种类型安全和更面向对象的查询。而Spring Data JPA支持JPA2.0的Criteria查询,相应的接口是JpaSpecificationExecutor。 Specification接口中只定义了如下一个方法: Predicate toPredicate ( Root<T> root, CriteriaQuery<?> query, CriteriaBuilder cb ) ; 先简单了解JPA2.0的Criteria查询: Criteria 查询是以元模型的概念为基础的,元模型是为具体持久化单元的受管实体定义的,这些实体可以是实体类,嵌入类或者映射的父类。 CriteriaQuery接口:代表一个specific的顶层查询对象,它包含着查询的各个部分,比如:select 、from、where、group by、order by等注意:CriteriaQuery对象只对实体类型或嵌入式类型的Criteria查询起作用。 Root接口:代表Criteria查询的根对象

Hibernate Criteria contains-in on an association to a table

爷,独闯天下 提交于 2020-01-03 19:08:29
问题 I have a Hibernate mapping that looks something like this: <class name="MyEntity"> <set name="scalarSet" table="(select fk, scalar_value from other_table)"> <key column="fk"/> <property column="scalar_value" type="long"/> </set> </class Given this, how do I query such that a value of MyEntity.scalarSet (which is Set) is in a another collection. Something like: criteria.add(Restrictions.in("scalarSet", targetList)); [edit] I've also tried Restriction.sqlRestriction(..). The sql query that I

Grails criteria select when hasMany hasn't any elements

空扰寡人 提交于 2020-01-02 23:26:09
问题 I have the classes: class Course{ String name static hasMany = [ studentGrades: StudentGrade ] } class StudentGrade{ String name int grade } How can I make a criteria to get the courses without any student grade? 回答1: You could use the isEmpty criterion method: def c = Course.createCriteria() def results = c.list { isEmpty("studentGrades") } See the docs for further informations. 来源: https://stackoverflow.com/questions/10429023/grails-criteria-select-when-hasmany-hasnt-any-elements

Hibernate Criteria API equivalent to HQL select clause?

可紊 提交于 2020-01-02 05:08:06
问题 I'd like to have a combined query for two persistent classes. In HQL this could be achieved by the select clause, select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr In the above example, Family is a conbined class with DemesticCat as its construtor params What is the Criteria equivalent of the HQL select clause ? 回答1: You'll have to use a ResultTransformer for this. The Hibernate 3.2: Transformers for HQL and SQL blog