hibernate-criteria

Hibernate CriteriaBuilder to join multiple tables

大城市里の小女人 提交于 2019-12-03 02:06:22
I'm trying to join 4 tables using hibernate criteriabuilder.. Below are the tables respectively.. ` @Entity public class BuildDetails { @Id private long id; @Column private String buildNumber; @Column private String buildDuration; @Column private String projectName; } @Entity public class CodeQualityDetails{ @Id private long id; @Column private String codeHealth; @ManyToOne private BuildDetails build; //columnName=buildNum } @Entity public class DeploymentDetails{ @Id private Long id; @Column private String deployedEnv; @ManyToOne private BuildDetails build; //columnName=buildNum } @Entity

When to use Hibernate projections?

╄→尐↘猪︶ㄣ 提交于 2019-12-03 01:39:33
问题 I am a little confused about Hibernate's projections and criteria . When to use projections and when to use criteria? 回答1: They're not mutually exclusive, you can use both at the same time. Projections are generally used in the context of some Criteria. To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate

How to make HIbernate fetch all properties of root entity and only specific properties of associated entity?

无人久伴 提交于 2019-12-03 00:31:10
I have root entity Hostel and its single association User owner . When I fetch Hostel entity I need to eagerly fetch User owner , but only owner 's 3 properties : userId,firstName,lastName. For now my criteria query is : Criteria criteria = currenSession().createCriteria(Hostel.class); criteria.add(Restrictions.ge("endDate", Calendar.getInstance())); if (StringUtils.notNullAndEmpty(country)) { criteria.add(Restrictions.eq("country", country)); } Long count = (Long) criteria .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY) .setProjection(Projections.rowCount()).uniqueResult(); criteria

Hibernate criteria query multiple criteria

牧云@^-^@ 提交于 2019-12-02 21:18:27
In my current project I've faced a problem of getting entities with hibernate criteria query. I have the following entities: Professor, which contains a list of students Student, which contains a list of assignments. Assignment, which contains id of student to which it is assigned to. Now, I want to get all assignments relative to the professor, i.e. all assignments Professor assigned to his students. This query shows what I want to implement in criteria query. select * from Assigment p, Student a, Professor c where p.studentid = a.id and a.proffid = c.id and c.id = 2411; How can I implement

How to use Hibernate Criteria objects for multiple and/or conditions

こ雲淡風輕ζ 提交于 2019-12-02 16:50:54
I need to create a Hibernate criteria restriction that ors 3 Conditions. The problem is that the last condition is acutally to conditions using the AND operator. My first condition: Criterion startInRange = Restrictions.between("expectedStartCanonicDate", rangeStart, rangeEnd); My second condition: Criterion endInRange = Restrictions.between("expectedCompletionCanonicDate", rangeStart, rangeEnd); MY third condition needs to AND the following two conditions together: criteria.add(Restrictions.le("expectedStartCanonicDate", rangeStart)); criteria.add(Restrictions.ge(

When to use Hibernate projections?

这一生的挚爱 提交于 2019-12-02 15:07:12
I am a little confused about Hibernate's projections and criteria . When to use projections and when to use criteria? They're not mutually exclusive, you can use both at the same time. Projections are generally used in the context of some Criteria. To put it simple, Hibernate Projections are used in order to query only a subset of the attributes of an entity or group of entities you're querying with Criteria. You can also use Projections to specify distinct clauses and aggregate functions like max , sum and so on. It's like referring to which data you're fetching. Like modifying the select

Joining on multiple fields in a NHibernate Criteria query

血红的双手。 提交于 2019-12-02 10:09:43
问题 I have a Dept table and a Emp table. I need to join these two table in such a way that the where clause looks something like this: where dept.deptId = emp.DeptId and dept.deptName = emp.empTrainingName I tried this: Criteria criteria = session.createCriteria(Dept.class).createAlias("empMap","id"); Using this, the first where condition i.e. dept.deptId = emp.DeptId is performed. But I am not sure how to compare dept.deptName with emp.empTrainingName . How do I do this using the Criteria API in

Hibernate Criteria Return parent record that have one-to-one child record not null?

北城余情 提交于 2019-12-02 07:49:57
I have a one-to-one relation like this The Parent @JsonAutoDetect @Entity @Table(name = "Parent") public class Parent{ private Integer id; private Child child; @Id @GeneratedValue(strategy= GenerationType.AUTO) @Column (name="idparent") public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent") @JoinColumn(name="idchild", nullable=true) public Child getChild() { return child; } public void setChild(Child child) { child.setParent(this); this.child = child; } } and the child

Joining on multiple fields in a NHibernate Criteria query

試著忘記壹切 提交于 2019-12-02 04:17:13
I have a Dept table and a Emp table. I need to join these two table in such a way that the where clause looks something like this: where dept.deptId = emp.DeptId and dept.deptName = emp.empTrainingName I tried this: Criteria criteria = session.createCriteria(Dept.class).createAlias("empMap","id"); Using this, the first where condition i.e. dept.deptId = emp.DeptId is performed. But I am not sure how to compare dept.deptName with emp.empTrainingName . How do I do this using the Criteria API in NHibernate? Criteria criteria = session.createCriteria(Dept.class, "department") .createAlias("empMap"

One to Many search using AND condition

纵然是瞬间 提交于 2019-12-02 04:04:54
I have the following product which contain many colors. I wish to find the product which contain at least RED and GREEN. Product class String id; List<Color> colors{}; Color class id color kindly ignore the syntax error. I'm able to use the following to search OR condition. Criteria criteria = createCriteria(); criteria.createAlias("colors","colors"); List<String> colorsList = new LinkedList(); colorsList.add("GREEN"); colorsList.add("RED"); criteria.add(Restriction.in("colors.color",colorsList); The above will give me products which has red or green in their colors BUT not products which