criteria

Criteria API returns a too small resultset

試著忘記壹切 提交于 2019-12-21 03:34:10
问题 How is this possible, I have to following criteria Criteria criteria = getSession().createCriteria(c); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.add(Restrictions.eq("active",true)); List list = criteria.list(); The size of list is now 20. If I add a max results to the criteria, Criteria criteria = getSession().createCriteria(c); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); criteria.setMaxResults(90); criteria.add(Restrictions.eq("active",true));

Hibernate Criteria / Query on object properties

允我心安 提交于 2019-12-20 12:39:05
问题 I have a class AppUser ; class AppUser { private String firstName; private String lastName; //-- getters and setters } I also have another class Student ; class Student { private AppUser appUser; private Date dateOfBirth; //-- getters and setters } How would i search for Student John Doe , firstName John, lastName Doe? Had it been the date of birth property, i would create a Criteria and add an equality Restriction ( Restristions.eq ) on the date. How would i do it for lastName and firstName

JPQL “NOT MEMBER OF” query using criteria API

你离开我真会死。 提交于 2019-12-20 05:18:18
问题 Given the following JPA annotated entity classes: @Entity @Table("foo") public class Foo { @Id private int id; @Column(name="name") private String name; @ManyToMany @JoinTable(name = "foo_tags", joinColumns = {@JoinColumn(name = "foo")}, inverseJoinColumns = {@JoinColumn(name = "tag")}) private Collection<Tag> tags; ... } @Entity @Table(name = "tag") public class Tag { @Id private String tag; ... } I'm trying to formulate a query to get all Foo instances that lack a given tag. The following

Grails criteria query checking `OR` logic

拜拜、爱过 提交于 2019-12-20 04:23:32
问题 I having grails criteriaQuery where I am checking OR logic againist a single state variable like this: or { eq("status", Status.ONE) eq("status", Status.TWO) eq("status", Status.THREE) } This code is working fine, My question is, as I am checking OR logic againist a single state, Is there any way to optimize this code like eq("status",Status.ONE || Status.TWO || Status.THREE) Thanks in advance. 回答1: You can use 'in'( "status", [Status.ONE, Status.TWO, Status.THREE] ) Or just 'in'( "status",

Regular expression with criteria

假装没事ソ 提交于 2019-12-20 03:38:10
问题 I have a table in which certain words or word groups are stored. I want to select entries which start with an uppercase letter, cointain no space and contain only letters. My SQL looks like this: select word from words where w_id > 100 AND word REGEXP '^[A-Z][A-Za-z]*$' limit 2000; How do I do the same thing using criteria? 回答1: Try this: List words = session.createCriteria(Word.class) .setProjection(Projections.property("word")) .add(Restrictions.and(Restrictions.gt("w_id",100), Restrictions

Excel averageifs with or function

廉价感情. 提交于 2019-12-20 02:31:44
问题 I am using the averageifs function, and have one column where I need to calculate the average if either of the criteria are true. I have tried using the OR function, and tried the curly brackets, but both give me errors. =AVERAGEIFS(N1:N612,I1:I612,{"FL","IF"}) There are more ranges, but the coding for those is fine. To be clear, I want to return an average if column "I" contains (specifically) the letters FL, OR the letters IF. Any other letters should mean that entry is not averaged. TIA!

Excel averageifs with or function

こ雲淡風輕ζ 提交于 2019-12-20 02:29:09
问题 I am using the averageifs function, and have one column where I need to calculate the average if either of the criteria are true. I have tried using the OR function, and tried the curly brackets, but both give me errors. =AVERAGEIFS(N1:N612,I1:I612,{"FL","IF"}) There are more ranges, but the coding for those is fine. To be clear, I want to return an average if column "I" contains (specifically) the letters FL, OR the letters IF. Any other letters should mean that entry is not averaged. TIA!

How to set more than 2 Expression in Expression.Or

二次信任 提交于 2019-12-19 16:52:24
问题 I want to create a query which has more than 3-4 Expression.Or ? But Expression.Or just let me to add two Expressions inside it. if (!string.IsNullOrEmpty(keyword)) query .Add(Expression.Or( Expression.Like("Name", keyword, MatchMode.Anywhere), Expression.Like("LastName", keyword, MatchMode.Anywhere))) .Add(Expression.Or( Expression.Like("Email1", keyword, MatchMode.Anywhere), Expression.Like("Email2", keyword, MatchMode.Anywhere))); The code above generates "Name like %this% or LastName like

Order by relation count in NHibernate

有些话、适合烂在心里 提交于 2019-12-19 12:12:33
问题 I have a datastructure like this: public class User { public Guid Id {get;set;} public string Name {get;set;} public IList<Books> Books {get;set} } I have been struggeling with making it possible to sort the users by the count of bookmarks (one-to-many relation). I have tried various approaches with both linq, criteria and queryover, but with no luck, and therefore hope one of you could help. I am using paging, since I have quite a few users, so the solution needs to do the query on the SQL

Order by relation count in NHibernate

扶醉桌前 提交于 2019-12-19 12:12:08
问题 I have a datastructure like this: public class User { public Guid Id {get;set;} public string Name {get;set;} public IList<Books> Books {get;set} } I have been struggeling with making it possible to sort the users by the count of bookmarks (one-to-many relation). I have tried various approaches with both linq, criteria and queryover, but with no luck, and therefore hope one of you could help. I am using paging, since I have quite a few users, so the solution needs to do the query on the SQL