criteria

JPA CriteriaBuilder conjunction criteria into a disjunction criteria

你说的曾经没有我的故事 提交于 2020-01-01 15:36:06
问题 I need to replicate this query into JPA CriteriaBuilder code: .... where article.client_id = 1 and article.price > 0 and ( article.code like '%this is statement%' or article.oem_code like '%this is statement%' or ( article.description like '%this%' and article.description like '%is%' and article.description like '%statement%' ) ) and here's my code: ... Root<Article> article = cq.from(Article.class); List<Predicate> predicates = new ArrayList<Predicate>(); predicates.add(cb.equal(article.get

Referring to a Subform from a Query

北城余情 提交于 2019-12-31 07:16:11
问题 In MS Access 2010, I have a Query which quotes the following in the Criteria; [Forms]![frm_Add_Item_Subform].[ActiveControl].[Caption] This lets me use the "Caption" text of a Button within the query. The following code is on the Button to capture the click. Private Sub cmdClickMe_Click() Debug.Print Me.cmdClickMe.Caption Debug.Print Screen.ActiveControl.Caption End Sub I obtained information on how to do this at the following StackOverflow URL. use caption of pressed button from main form in

C++ struct sorting

五迷三道 提交于 2019-12-31 04:00:52
问题 I have a vector of custom Struct that needs to be sorted on different criteria each time Implementing operator < will allow only one criteria But I want to be able to specify sorting criteria each time I call C++ standard sort. How to do that? Please note it is better to be efficient in running time.. Thanks 回答1: You can define what comparison function to use in each run of the sort algorithm by using the third argument: template <class RandomAccessIterator, class StrictWeakOrdering> void

JPA / Hibernate: CriteriaBuilder - How to create query using relationship object?

╄→гoц情女王★ 提交于 2019-12-30 10:36:35
问题 I have the following four tables: SCHEDULE_REQUEST TABLE: ID, APPLICATION_ID (FK) APPLICATION TABLE: ID, CODE USER_APPLICATION TABLE: APPLICATION_ID (FK), USER_ID (FK) USER TABLE: ID, NAME Now I wanted to create a CriteriaBuilder where condition is to select ScheduleRequests for specified user Ids. I have the following codes: List<User> usersList = getSelectedUsers(); // userList contains users I wanted to select CriteriaBuilder builder = getJpaTemplate().getEntityManagerFactory()

Case-insensitive ordering using Hibernate Criteria

人盡茶涼 提交于 2019-12-30 06:15:08
问题 I have a query created with Hibernate Criteria like this: Criteria criteria = db.getSession().createCriteria(Vendor.class); criteria.addOrder(Property.forName("shortName").asc()); List<Vendor> vendorList = criteria.list(); I would like the ordering to be case-insensitive, equivalent to the HQL query FROM Vendor ve ORDER BY lower(ve.shortName) How can I achieve this using Hibernate Criteria? 回答1: criteria.addOrder(Order.asc("shortName").ignoreCase()); 来源: https://stackoverflow.com/questions

mongodb操作

£可爱£侵袭症+ 提交于 2019-12-29 05:13:35
mongodb 的分页查询: public List<NoticeSentRecordDto> select(NoticeSelectInfo noticeSelectInfo){ Query query = new Query().with(new Sort(Sort.Direction.DESC, "createTime")); if (noticeSelectInfo.getCurrPage() != null && noticeSelectInfo.getPageSize() != null) { query.skip((noticeSelectInfo.getCurrPage()-1)*noticeSelectInfo.getPageSize()) .limit(noticeSelectInfo.getPageSize()); } query.addCriteria(Criteria.where("isDeleted").is(0)); if(!StringUtils.isEmpty(noticeSelectInfo.getType())){ query.addCriteria(Criteria.where("type").is(noticeSelectInfo.getType())); } return template.find(query,

Ordering results by computed value in Hibernate

旧街凉风 提交于 2019-12-28 15:35:51
问题 I have a table Player with columns id, name, wins, games_played. I mapped it to a class Player. I want to do the following query in Hibernate (preferably with Criteria, if not possible with Criteria HQL will also help) select * from Player order by (wins / games_played) I expect to get List<Player> sorted by their win ratio. Thanks for the answer Palo 回答1: Hibernate doesn't support arithmetics expressions in the order by clause. Quoting the section 14.12. The group by clause of the Hibernate

Using Hibernate's Criteria and Projections to Select Multiple Distinct Columns

為{幸葍}努か 提交于 2019-12-28 12:15:27
问题 Using Hibernate's Criteria, I want to execute the equivalent of: select distinct uspscity, state from citycomplete where USPSCITY = 'HOUSTON' I thought doing the following would yield the results I wanted: ProjectionList projList = new ProjectionList(); projList.add(Projections.distinct(Projections.property("id.state"))); projList.add(Projections.distinct(Projections.property("id.uspsCity"))); criteria.setProjection(projList); But, what this actually does is execute something like: select

Java Criteria API join self referencing entity

眉间皱痕 提交于 2019-12-25 11:28:08
问题 I'm trying to do a nested join on a self referencing entity, please bear with me, it will make sense :) Thing.java class Thing { Integer something; Person owner; } Person.java class Person { String name; Person parent; } Note: A Person with parent=null means that they are a parent, and cannot have a parent. It's an alien world! :P Query: Root<Thing> root = query.from(Thing.class); Join<Thing, Person> ownerJoin = root.join(Thing_.owner); Join<Person, Person> parentJoin = ownerJoin.join(Person_

Java Criteria API join self referencing entity

自古美人都是妖i 提交于 2019-12-25 11:27:04
问题 I'm trying to do a nested join on a self referencing entity, please bear with me, it will make sense :) Thing.java class Thing { Integer something; Person owner; } Person.java class Person { String name; Person parent; } Note: A Person with parent=null means that they are a parent, and cannot have a parent. It's an alien world! :P Query: Root<Thing> root = query.from(Thing.class); Join<Thing, Person> ownerJoin = root.join(Thing_.owner); Join<Person, Person> parentJoin = ownerJoin.join(Person_