hibernate-criteria

Hibernate CriteriaAPI and like operator. Swap operands + database independent concatenation - is it possible?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-25 11:55:11
问题 Intro I have a weird task - to write on Hibernate Criteria API (i.e. in database independent style) SQL query similar to select * from branch b where '2/5/3/' like b.hier_path + '%' where + is concatenation operator. Concatenation operator is database dependent '+' in MS SQL, '||' in Oracle etc. I must use Criteria API (and no way to switch to HQL). Problem #1 - like operator Unfortunately, Hibernate allows to write only Criteria based on Java object property: pCriteria.createCriteria(Branch

Projection-Grouping-Detached Criteria

血红的双手。 提交于 2019-12-25 09:37:32
问题 public List<Staffing> upcoming(){ List<Staffing> staffing = new ArrayList<Staffing>(); Criteria criteria = getCriteria(); criteria.add(Restrictions.isNotNull("startDate")).add(Restrictions.le("startDate", new Date())); criteria.add(Restrictions.isNotNull("endDate")).add(Restrictions.ge("endDate", new Date())); criteria.add(Restrictions.eq("softDelete", false)); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("user"))); DetachedCriteria maxDateQuery =

Projection-Grouping-Detached Criteria

无人久伴 提交于 2019-12-25 09:37:06
问题 public List<Staffing> upcoming(){ List<Staffing> staffing = new ArrayList<Staffing>(); Criteria criteria = getCriteria(); criteria.add(Restrictions.isNotNull("startDate")).add(Restrictions.le("startDate", new Date())); criteria.add(Restrictions.isNotNull("endDate")).add(Restrictions.ge("endDate", new Date())); criteria.add(Restrictions.eq("softDelete", false)); criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("user"))); DetachedCriteria maxDateQuery =

org.hibernate.QueryException: Criteria objects cannot be created directly on components

纵然是瞬间 提交于 2019-12-25 04:27:44
问题 I face above issue when try to sort based on an embedded field; eg: I try to sort with the property tObservation.raw.waterLevel.metre . But getting following exception. Caused by: org.hibernate.QueryException: Criteria objects cannot be created directly on components. Create a criteria on owning entity and use a dotted property to access component property: tObservation.raw at org.hibernate.loader.criteria.CriteriaQueryTranslator.getPathInfo(CriteriaQueryTranslator.java:251) I create aliases

Converting MySQL query to Hibernate Criteria

和自甴很熟 提交于 2019-12-25 03:14:11
问题 SELECT * FROM test.pchi new INNER JOIN rlhi old ON new_id = old.menu_id where new.name='?' Similar to: Select * from db.employee emp INNER JOIN db.table on emp_tableID = table.id where emp.name = '?' If you could tell me how to do a projection, that would be awesome... as in: Select emp.name, emp.sex, table.brand from .... I tried using fetch, but I'm very new to this and keep getting some weird errors. Could someone please demonstrate how to do this? How about this? sess.createCriteria(pchi

get updated row in one to many mapping using hibernate

可紊 提交于 2019-12-24 16:53:21
问题 I have two entities Issue and Issue_Tracker . I have joined both table in an one to many mapping. In Issue_Tracker , We can have multiple entries like issue_id tracker_status tracked_time 123 Assigned 1/8/2013 11:44 123 Assigned 1/8/2013 11:45 123 Completed 1/8/2013 11:52 32 Assigned 1/9/2013 16:46 33 Assigned 1/9/2013 16:47 33 Cancel 1/9/2013 16:49 I want to Order the Issue_tracker entity by tracked_time so I can get only last update tracker_status .I am using criteria to get data,However I

get updated row in one to many mapping using hibernate

旧街凉风 提交于 2019-12-24 16:53:09
问题 I have two entities Issue and Issue_Tracker . I have joined both table in an one to many mapping. In Issue_Tracker , We can have multiple entries like issue_id tracker_status tracked_time 123 Assigned 1/8/2013 11:44 123 Assigned 1/8/2013 11:45 123 Completed 1/8/2013 11:52 32 Assigned 1/9/2013 16:46 33 Assigned 1/9/2013 16:47 33 Cancel 1/9/2013 16:49 I want to Order the Issue_tracker entity by tracked_time so I can get only last update tracker_status .I am using criteria to get data,However I

Hibernate eager loading with query

拈花ヽ惹草 提交于 2019-12-24 06:49:53
问题 The model is that a user can have many LoginSessions (LogginSession can be related to only one user). What I am trying to achieve is bring the user with related LoginSession (which's token provided in the query). All of that I am trying to do with only one query, and to do so I want to use eager loading, here is my code: I have this code: LoginSession loginSession = new LoginSession(); loginSession.setToken(sessionToken); //Example loginSessionExample = Example.create(loginSession); Criteria

Hibernate one-to-many mapping eager fetch not working

风流意气都作罢 提交于 2019-12-24 03:06:17
问题 There is a one to many relationship between College & student entities. College @Entity public class College { private int collegeId; private String collegeName; private List<Student> students; @Id @GeneratedValue public int getCollegeId() { return collegeId; } public void setCollegeId(int collegeId) { this.collegeId = collegeId; } public String getCollegeName() { return collegeName; } public void setCollegeName(String collegeName) { this.collegeName = collegeName; } @OneToMany(targetEntity

Hibernate Criteria API - accessing joined properties

谁说胖子不能爱 提交于 2019-12-24 00:34:35
问题 I have a pretty complex criteria, which I use to retrieve, sort and page server-side data. I stripped down the following excerpt: // create criteria over a bunch of tables... Criteria testCriteria = getSession().createCriteria(PriceRequest.class) .setResultTransformer(CriteriaSpecification.DISTINCT_ROOT_ENTITY) .setFetchMode("pricedBy", FetchMode.JOIN) .setFetchMode("canceledBy", FetchMode.JOIN) .setFetchMode("product", FetchMode.JOIN) .setFetchMode("product.underlyings", FetchMode.JOIN)