hibernate-criteria

Hibernate Child Collection Limited When Using Left Join in Criteria

核能气质少年 提交于 2019-12-12 08:56:14
问题 When using hibernate criteria just altering the join type affects the results of the child collections of the root domain class. For instance, having class Parent have a one-to-many relationship with class Child with the following data: Parent | id | Name | | 1 | Parent 1 | Child | id | parent_id | Name | | 1 | 1 | Child1 | | 2 | 1 | Child2 | Using the following hibernate criteria returns the 1 parent row, and accessing the child collection results in the two rows being returned: session

Hibernate Criteria: Left Outer Join with restrictions on both tables

醉酒当歌 提交于 2019-12-12 07:26:24
问题 I am doing a LEFT OUTER JOIN, but I am only able to apply Restrictions on the first table. Is there a way ti apply on the second table as well? Here is my code: Criteria criteria = this.crudService .initializeCriteria(Applicant.class).setFetchMode("products", FetchMode.JOIN);. This works (applicant has an applicantName property): criteria.add(Restrictions.eq("applicantName", "Markos") Neither of these works (product has a productName property) criteria.add(Restrictions.eq("productName",

Count rows on distinct select with multiple columns

人走茶凉 提交于 2019-12-12 06:14:18
问题 I have been searching for some time but not found enough answers to do this myself. I have an MsSQL that looks like this: select count(*) from ( select distinct supplierName, supplierNr from dbo.InvoiceTypeBean ) as a This returns what I want using pure SQL But i need this in hibernate using criteria and/or detachedcriteria: The detached criteria part: DetachedCriteria dCriteria = DetachedCriteria.forClass(clazz); ProjectionList p = Projections.projectionList(); p.add(Projections.property(

Hibernate criteria, distinct association property

老子叫甜甜 提交于 2019-12-12 05:59:57
问题 Say I have at least these two entities: class Person { String firstname, lastname; Address address; ManyOtherPropertiesAndEntities ...; } class Address { String street; Country country; } Now, I would like to query the Person table and ONLY Persons that live on different streets. That is, ignore all Persons that live on same street , and return only one of these Person, any one. How can I perform such a query? Is that possibly using Criteria ? Criteria criteria = session.createCriteria(Person

Hibernate Criteria API on Child table

蹲街弑〆低调 提交于 2019-12-12 03:22:28
问题 Here is the 2 DTO: class Item { private Integer id; private Integer serviceId; private String itemGuid; private String meterId; private Integer resourceId; private String meterName; private String description; private String category; private String subCategory; private List rates; } public class Rates { private Integer id; private Double unit; private Double price; private String field1Unique; private String field2Unique; private String field1Index; private String field2Index; private String

Hibernate tuple criteria queries

£可爱£侵袭症+ 提交于 2019-12-12 00:50:20
问题 I am trying to create a query using hibernate following the example given in section 9.2 of chapter 9 The difference with my attempt is I am using spring MVC 3.0. Here is my Address class along with the method i created. @RooJavaBean @RooToString @RooEntity @RooJson public class Address { @NotNull @Size(min = 1) private String street1; @Size(max = 100) private String street2; private String postalcode; private String zipcode; @NotNull @ManyToOne private City city; @NotNull @ManyToOne private

Nested Query in Hibernate using Criterion

删除回忆录丶 提交于 2019-12-11 21:05:29
问题 I have a following query where I have to select rows from temporary table created by subquery. select x, y, x from (select x, y, z from some_table where x between x1 and x2) where y like 'y1' order by z by desc I have to use Criteria for fetching result from database I have gone through several examples and documentation for handling subqueries using criteria and detached criteria. I have used Detached query but it is not serving the purpose or I am missing something. I have used following

Hibernate Criteria: How to create a query for many search fields?

蓝咒 提交于 2019-12-11 16:36:23
问题 I need to fetch details from DB if any of the fields are entered, the fields are as below Date Code Action Status UserName Application. Kindly help me as any of the fields can be entered and not necessarily all values need to entered. Thanks & Regards, Jafer 回答1: public List searchAccommodation(Date startDate, Date endDate, Country country, AccommodationType type, Integer capacity) Criteria criteria = session.createCriteria(Accommodation.class); if (startDate != null) { criteria.add

Hibernate Lazy Loading makes criteria slow to run

不羁岁月 提交于 2019-12-11 13:49:13
问题 I am experiencing a problem with hibernate and lazy loading of objects. basically I want to load an class which has an eagerly loaded field and not load the lazy fields of child classes Take the following QuestionVO class @Entity @Table(name = "question") public class QuestionVO extends BaseDAOVO implements Serializable { /** * */ private static final long serialVersionUID = -5867047752936216092L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", unique = true,

Last Record of one to many relation Hibernate Criteria

家住魔仙堡 提交于 2019-12-11 10:47:28
问题 I need to get last record and the main record of one-to-many relation with Hibernate criteria. The Pseudo-Sql show the query I want to execute Table1(Master) Table2(Details) Select * from Table1 tab1, Table2 tab2 where tab2.tab1id == tab1.id and tab2.date == ( select Max(date) from table2 where table2.tab1id == tab1.id) 回答1: I did it!!! DetachedCriteria maxFecha = DetachedCriteria .forClass(CambiosEstado.class, "cambio") .setProjection(Projections.max("fecha")) .add(Property.forName("cambio