hibernate-criteria

Grails : how to best construct a hibernate criteria builder to search 'hasMany' relationships with domain instance

假装没事ソ 提交于 2019-12-18 07:23:16
问题 I am working on a grails project and would like to leverage hibernate criteria builders to search for instances of a domain object. I would like to find instances where one of the 'hasMany' relationships contains domain object with certain ids. Here is an example of what I mean. Domain Objects class Product { static hasMany = [ productOptions: ProductOption ] } class ProductOption{ Option option static belongsTo = [ product: Product ] } class Option{ String name } This is a simplified example

How to implement with hibernate criteria Object the select query with inner join

為{幸葍}努か 提交于 2019-12-18 04:21:06
问题 I'm new with Hibernate and Criteria Query. So I have implemented the query in HQL: select A.mobilephone B.userNick C.creditCard from mobile_table A inner join user_table B on A.codmobile=B.codmobile inner join Credit C on A.mobileCredit= C.mobileCredit How can I implement it with Hibernate Criteria Object? 回答1: Your example is just a native SQL , not the HQL . Anyway , you can use the following methods from the Criteria API to construct the desired Criteria object : Use the setProjection

Hibernate Group by Criteria Object

核能气质少年 提交于 2019-12-17 07:21:46
问题 I would like to implement the following SQL query with Hibernate Criteria: SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name <operator> value GROUP BY column_name I have tried to implement this with Hibernate Criteria but it didn't work out. Can anyone give me an example how this can be done with Hibernate Criteria? Thanks! 回答1: Please refer to this for the example .The main point is to use the groupProperty() , and the related aggregate functions provided

How to use a subquery instead of a joined query to get correct count with hibernate

落花浮王杯 提交于 2019-12-14 03:59:35
问题 assuming I have following two tables (Cats with Kittens): ==== Cat.java ==== @Id @GeneratedValue( strategy = GenerationType.IDENTITY ) private long id; @Column( unique = true, nullable = false ) private String name; @OneToMany @JoinColumn( name = "cat_id" ) private List<Kitten> kitten; ==== Kitten.java ==== @Id @GeneratedValue( strategy = GenerationType.IDENTITY ) private long id; @Column( unique = true, nullable = false ) private String name; with the following data Cat(id, name) Cat(1, "Cat

Pagination Issue while join in Hibernate Criteria

泪湿孤枕 提交于 2019-12-13 12:38:38
问题 I want to have the pagination after the multiple table join in criteria. The issue is: The duplicate records generated when I join the tables. The pagination applied to the record set(With duplication). I use this criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); to remove the duplicated records. For example: Normally I got 10 records after applying the removing duplication. When I set my start index as 1 and end index as 5 , I am supposed to get 5 records but it returns 2 or 3

How to write the Criteria queries dynamically?

佐手、 提交于 2019-12-13 04:42:09
问题 Hi I am writing a criteria query to fetch employees. I am using the Generic type as parameter for this method. The user can pass the class dynamically which class they want. For my employee class I want to add some restriction dynamically like if employee is true then I want to fetch that record, otherwise that record should not be fetch. But if the user gives only record without any restriction, than it has to fetch all records. public static <T> List getRowCount(Class<T> classname) {

Hibernate criteria query

早过忘川 提交于 2019-12-12 17:39:02
问题 I am trying to execute a subquery using Hibernate criteria api but not been able to figure out completely how to go about it. Assuming there are 2 tables, SHOPS and EMPLOYEES, where SHOPS has all the shops information and EMPLOYEES is a big table of all the employess in all the shops (No foreign keys set). I am trying to write a query, which retrieves the shop id and address from the SHOPS table and then retrieves the number of employess in a shop by a join and count on EMPLOYEES table.

Including the max and offset criteria inside GORM criteriaBuilder returns an error

我怕爱的太早我们不能终老 提交于 2019-12-12 12:27:13
问题 Can I make this code shorter? if(count == null && from = null) { creditAdviceList = CreditAdvice.findAll { ilike('id', "%$idFilter%") ..... ilike('statusCode', statusCodeFilter) } } else if(count != null && from == null) { creditAdviceList = CreditAdvice.findAll(max: count) { ilike('id', "%$idFilter%") ..... ilike('statusCode', statusCodeFilter) } } else if(count == null && from != null) { creditAdviceList = CreditAdvice.findAll(offset: from) { ilike('id', "%$idFilter%") ..... ilike(

Hibernate Criteria Left Excluding JOIN

萝らか妹 提交于 2019-12-12 09:47:52
问题 I have no ideas how to do it using Hibernate Criteria SELECT * FROM Table_A A LEFT JOIN Table_B B ON A.Key = B.Key WHERE B.Key IS NULL there is Hibernate mapping like @Entity class A{ @Id @Column(name = "ID") private String ID; ... // fields } @Entity class B{ ... // fields @OneToOne(fetch = FetchType.EAGER) @JoinColumn(name = "A_ID", referencedColumnName = "ID") @Cascade(CascadeType.DETACH) private A a; ... // fields } So I need to get list of all A which are not referred by B 回答1: Not tried

org.hibernate.QueryException: could not resolve property: filename

两盒软妹~` 提交于 2019-12-12 09:28:47
问题 I am using Hibernate Criteria to get values from column filename in my table contaque_recording_log . But when I'm getting the result, it throws an exception org.hibernate.QueryException: could not resolve property: filename of: com.contaque.hibernateTableMappings.contaque_recording_log My table bean is: import java.util.Date; import javax.persistence.*; @Entity @Table(name="contaque_recording_log") public class contaque_recording_log implements java.io.Serializable{ private static final long