hibernate-criteria

Issue with selecting max id rows using criteria query / hibernate query?

断了今生、忘了曾经 提交于 2019-12-07 16:47:19
问题 I am unable to select the rows where TestId is max for respective student, I wrote the code as follows which does not get the required output. my code is as follows, Criteria c = sessionFactory.getCurrentSession().createCriteria(student.class).setProjection(Projections.projectionList().add(Projections.property("answer"),"answer")); c.add(Restrictions.eq("surveyId",send_Survey)); //c.add(Restrictions.eq("testId", "1" )); //c.setProjection(Projection.max("testId")); c.addOrder(Order.desc(

How to use Oracle query hint in Hibernate

无人久伴 提交于 2019-12-07 16:28:52
问题 I am trying to use Oracle hint in Hibernate to call force index, but didn't find any proper API in Hibernate 3.6.10.Final. I somehow tried with projections in Hibernate criteria: proList.add(Projections.sqlProjection("/*+ INDEX_DESC(CONTACT_USER_FK_I) */", new String[]{}, new Type[]{})); proList.add(Projections.property("objectId")); criteria.setProjection(proList); return criteria.list(); But I am getting the exception below: EXCEPTION Caused by: 8 SQL Error (could not execute query; SQL

Common criteria restriction in Hibernate for all queries for all tables

情到浓时终转凉″ 提交于 2019-12-07 09:55:34
I have already finished writing a lot of queries in hibernate for my project. Now my requirement has changed and a new column name ACTIVE is added in all the tables I have in MySql. I have no permission to deny the addition of ACTIVE column. The ACTIVE field can hold values true or false and I have to add that to the criteria too. So, I have been thinking is there a way I could add a criteria restriction in Hibernate that is kind of common to all the queries I make, instead of putting that criteria for every query I make? EDIT: Little misunderstanding I suppose, sorry for that, I was in hurry

Ignorecase for In-Criterion

故事扮演 提交于 2019-12-07 07:58:38
问题 i'd like to select items case insensitive with an In-Criterion with Hibernate Criteria API. E.g. Criteria crit = session.createCriteria(Item.class); crit.add(Restrictions.in("prop", valueList).ignoreCase()); Unfortunately the Criterion class doesn't has an ignoreCase method. HQL is not an alternative. 回答1: Get the source code of the Criterion class returned by Restrictions.in() ( InExpression ), and create another one which is similar but transforms all the elements of the value list to

hibernate update single column using criteria

雨燕双飞 提交于 2019-12-07 01:40:39
问题 I have a table that contains mamy columns and I want to update the one or few columns of the row without effecting remaining columns I can write query: update table as t set t.a=:a set t.b=:b where t.id=1 But seen I dont know which columns will be selected to update, and I think it is not a good idea to write every query for every scenarios. Well, I have to write query for every scenarios, but I am looking for a better way to update the table dynamically. I am thinking criteria would be a

Use Hibernate Criteria for filtering keys and values in Map

核能气质少年 提交于 2019-12-06 19:33:15
问题 I have the following persisted class: public class Code { @ElementCollection(targetClass = CodeValue.class) @MapKeyClass(CodeProperty.class) @JoinTable(name="code_properties") @CreateIfNull( value = false ) private Map<CodeProperty,CodeValue> propertiesMap = new HashMap<CodeProperty, CodeValue>(); ... } public class CodeProperty { private String name; ... } public class CodeValue { private String value; ... } And I'm trying to get a list of Code filtered by some properties I have in

Query @ElementCollection JPA

社会主义新天地 提交于 2019-12-06 04:24:40
问题 I have an Entity Transaction as following : @Entity class Transaction extends AbstractEntity<Long>{ private static final long serialVersionUID = 7222139865127600245L; //other attributes @ElementCollection(fetch = FetchType.EAGER, targetClass = java.lang.String.class) @CollectionTable(name = "transaction_properties", joinColumns = @JoinColumn(name = "p_id")) @MapKeyColumn(name = "propertyKey") @Column(name = "propertyValue") private Map<String, String> properties; //getters and setters } So,

How to group by projections with Hibernate

纵饮孤独 提交于 2019-12-06 03:53:40
I need to find a list of students that are in a specific group and located in a specific address along with their phone numbers in their location. My main issue is I can not retrieve phone numbers of each student as a collection. For example if I have student1,student2. Phone 1111 for student1 in location1 and phone 2222 and phone 3333 for student2 in location 1 and phone 444 for student2 in location2. Lets say I have Student1 Alex group1 1111 Location1 Street1 Student3 Jack group1 93939 Location2 Street4 Student7 Joe group2 22223 Location4 Street8 Student2 John group1 2222 3333 Location1

Hibernate Criteria Left Excluding JOIN

本小妞迷上赌 提交于 2019-12-06 01:08:23
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 Not tried it before, but something like this should work: select * from Table_A a where a not in ( select b.a from

How to use Oracle query hint in Hibernate

蹲街弑〆低调 提交于 2019-12-06 00:49:13
I am trying to use Oracle hint in Hibernate to call force index, but didn't find any proper API in Hibernate 3.6.10.Final. I somehow tried with projections in Hibernate criteria: proList.add(Projections.sqlProjection("/*+ INDEX_DESC(CONTACT_USER_FK_I) */", new String[]{}, new Type[]{})); proList.add(Projections.property("objectId")); criteria.setProjection(proList); return criteria.list(); But I am getting the exception below: EXCEPTION Caused by: 8 SQL Error (could not execute query; SQL [select /*+ INDEX_DESC(CONTACT_USER_FK_I) */, this_.CONTACT_ID as y0_ from R4GDEV01_MBW.CONTACT this_ w