criteria

Hibernate one-to-many search with Criteria

好久不见. 提交于 2019-12-05 16:10:48
I've got a Hibernate entity, called Event, which has a one-to-many metadata entity, EventData. Given the following Event: EventId: 1 EventHash: broccoli With the following EventDatas: EventDataId: 1 EventId:1 Field: tag Content: tagme EventDataId: 2 EventId: 1 Field: tag Content: anotherTag How do I create a Criteria query to retrieve the event which has BOTH tags "anotherTag" and "tagme"? In SQL, I'd join the event_data table once for each tag being searched for, but I can only seem to create one alias for the Event.EventData relationship, i.e. int inc = 0; Conjunction junc = Restrictions

LIKE restriction from the Hibernate Criteria API

◇◆丶佛笑我妖孽 提交于 2019-12-05 13:08:14
问题 I am trying to query PostgreSQL database using Hibernate's restriction criterion like() with a partial keyword: Criterion c1 = Restrictions.like("stateName", "Virg*"); cri.add(c1); return cri.list(); It doesn't return anything but Restrictions.like("stateName", "Virginia"); returns the correct record. How do I use partial like restrictions in Hibernate? EDIT: Got it working by doing something like this: public static List<Object> createQueryStringByRegex(Criteria cri, Parameters p) { String

Select … in equivalent in JPA2 criteria

≯℡__Kan透↙ 提交于 2019-12-05 11:50:27
Is there any way to perform a query like the following using JPA2 criteria APIs? select a from b where a in (1, 2, 3, 4) There's a way to do that using plain Hibernate, but we can't find anything like that in JPA2. Yes JPA 2 Critera supports returning a specific field from a entity and using a where clause which includes an in clause. I have included an example below which takes a JPQL and converts it to a similar JPA 2 Criteria-based option. JPQL: select b.a from B b where a in (1, 2, 3, 4) Criteria: CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder(); // assuming a is an

Hibernate Criteria API equivalent to HQL select clause?

霸气de小男生 提交于 2019-12-05 11:08:55
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 ? You'll have to use a ResultTransformer for this. The Hibernate 3.2: Transformers for HQL and SQL blog post gives the following example (where StudentDTO is a non-entity Bean): List resultWithAliasedBean = s

JPA Criteria Query API and order by null last

点点圈 提交于 2019-12-05 10:12:46
问题 My problem is null values must be last order by statement. My code snipshot below. I use javax persistance criteria builder. My query complicated. import javax.persistence.criteria.CriteriaBuilder; public Predicate getSomePredicate() { Predicate predicate = cb.conjunction();.... ...predicate.getExpressions().add(cb.and(cb.or(cb.and(v1, v2), cb.and(s1, s2)))); EOrderByType orderType = EOrderByType.values()[orderBy] ; switch (orderType) { case PRICE: cq.where(predicate).orderBy(cb.asc(root.get(

JPA Select Count Distinct

♀尐吖头ヾ 提交于 2019-12-05 07:29:31
问题 I need a relatively simple query, but JPA makes it kind of hard to create it. The SQL variant would look like this: SELECT COUNT(DISTINCT OrderID) AS DistinctOrders FROM Orders WHERE CustomerID=7; [Edit: OrderID is NOT the primary key. There can be more OrderId that are equals in the table] I need to set the CustomerID with a variable that is passed to my method. I found documentation on CriteriaQuery distinct() but I can't seem to wrap it all together. This is what I have so far:

Yii CDbCriteria Join

给你一囗甜甜゛ 提交于 2019-12-05 06:56:24
How I can write the query SELECT * FROM doc_docs dd JOIN doc_access da ON dd.id=da.doc_id AND da.user_id=7 with CDbCriteria syntax? You actually cant completely write that since you have to apply the criteria to an activerecord model to obtain the primary table, but assuming you have a DocDocs model you can do it like this: $oDBC = new CDbCriteria(); $oDBC->join = 'LEFT JOIN doc_access a ON t.id = a.doc_id and a.user_id = 7'; $aRecords = DocDocs::model()->findAll($oDBC); Although it might be a lot easier if you give your DocDocs model a relation with doc_access, then you don't have to use the

Solr的页面展示以及高亮显示

微笑、不失礼 提交于 2019-12-05 06:56:04
Solr主要是为了做搜索引擎,前台传来的数据,我们通过在solr中设置对应的域,来对solr库中的对应的字段进行中文分词检索,来返回map,前台获取。 代码展示:   前台传来一个map集合,带着所有关键字到后台获取列表集合 //高亮查询 @Override public Map<String, Object> searchList(Map<String, Object> map) { //不写泛型返回的话,会出现IO异常 Map<String,Object> map1 = new HashMap(); //获取前端传递的当前页码和展示数量 Integer pageNo = (Integer)map.get("pageNo"); Integer pageSize = (Integer)map.get("pageSize"); if (pageNo==null || pageNo<=0){ pageNo=1; } pageNo = (pageNo-1)*pageSize; //高亮查询 HighlightQuery query = new SimpleHighlightQuery(); //起始索引,是当前页码-1*当前展示数量 query.setOffset(pageNo); query.setRows(pageSize); //高亮属性的设置 HighlightOptions

How does hibernate use an empty string for an equality restriction?

最后都变了- 提交于 2019-12-05 06:34:44
I have a column that potentially has some bad data and I can't clean it up, so I need to check for either null or empty string. I'm doing a Hibernate Criteria query so I've got the following that returns incorrectly right now: Session session = getSessionFactory().openSession(); Transaction tx = session.beginTransaction(); Criteria myCriteria = session.createCriteria(Object); ... myCriteria.add(Restrictions.or(Restrictions.isNull("stringColumn"), Restrictions.eq("stringColumn", ""))); List<Objects> list = myCriteria.list(); I can't get it to properly return the results I'd expect. So as an

SpringDataSolr入门

只谈情不闲聊 提交于 2019-12-05 05:05:44
Spring Data Solr 入门 2.1 Spring Data Solr 简介 虽然支持任何编程语言的能力具有很大的市场价值,你可能感兴趣的问题是:我如何 将 Solr 的应用集成到 Spring 中 ? 可以, Spring Data Solr 就是为了方便 Solr 的开发所研制的一个框架,其底层是对 SolrJ (官方 API )的封装。 2.2 Spring Data Solr 入门小 Demo 2.2.1 搭建工程 (1) 创建 maven 工程, pom.xml 中引入依赖 < dependencies > <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data- solr </artifactId> <version> 1.5.5 .RELEASE</version> </dependency> < dependency > < groupId > org.springframework </ groupId > < artifactId > spring-test </ artifactId > < version > 4.2.4.RELEASE </ version > </ dependency > < dependency > < groupId