hibernate-criteria

Hibernate 5 change not to use fetch first rows only

老子叫甜甜 提交于 2020-06-23 06:33:35
问题 I'm using Hibernate 5.2 with oracle 11 which does not support fetch first rows only and I need to get back to old style hibernate. is there any hibernate configuration to do that ? 回答1: You can force Hibernate to use the Oracle 10g dialect, this way you will get the old limit rule with rownum instead of fetch first. Looking at the official documentation, you can force the dialect with this property: hibernate.dialect=org.hibernate.dialect.Oracle10gDialect Or, if you are using Spring Boot 2

Prevent SQL injection with Hibernate

≡放荡痞女 提交于 2020-05-16 20:34:18
问题 I'm going through Hibernate and I know that you can prevent SQL injection with HQL: String query1 = "from Obj where id = "+ id; String query2 = "from Obj where id = :id"; query1 is unsafe while query2 is safe. How can I achieve safe queries with Criteria? Is this already implemented or do I have to do something else? Criteria c = session.createCriteria(Obj.class); c.add(Restrictions.eq("id", 5)); 回答1: I'm going through Hibernate and I know that you can prevent SQL injection with HQL: It is a

JPA Criteria API filtering on subclasses' attribute

烈酒焚心 提交于 2020-03-23 08:18:04
问题 I have the following entity domain. Parent class @Entity public final class SupportModuleInteraction implements Serializable { @Id private Long id; @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL, mappedBy = "supportModuleInteraction") @OrderColumn private List<Event> events; // ... getters/setters/ other attributes ommitted } Child class hierachy @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "event_type") public abstract class Event

How to create Hibernate Criteria for multiple levels

匆匆过客 提交于 2020-02-03 00:16:07
问题 I am trying to design a query using hibernate criteria API. The goal is to get a filtered list of items stored at 3rd level in form of java.util.Set which match a particular value. Further the list should be filtered at the outer most level for another specific value. Below are the model classes that form a multi level relationship: Seller.java @Entity @Table(name="seller") public class Seller { private Integer id; private Set<Store> stores; @Id @GeneratedValue(strategy=GenerationType

How to have criteria from multiple entities Hibernate

喜夏-厌秋 提交于 2020-01-25 10:22:11
问题 I have entities like this: @Entity @Table(name = "titul") public class Titul { @OneToMany(mappedBy = "titul") private Set<Autorstvo> autorstvo; @Column (name = "nazov") private String nazov; } @Entity @Table(name = "autorstvo") public class Autorstvo { @ManyToOne @JoinColumn(name="id_autor") private Autor autor; } @Entity @Table(name = "autor") public class Autor { @Column (name = "meno") private String meno; @OneToMany(mappedBy = "autor") private Set<Autorstvo> autorstvo; } And i want to

How to filter an entity in hibernate with hibernate filters

风格不统一 提交于 2020-01-24 23:03:15
问题 I need to filter an entity in a list of objects, for example: public class Student { private int id; private List<Course> courses; } public class Course { private int id; private String name; private float note; private Classroom classroom; } public class Classroom { private int id; private String classroom; } How to obtain a student object with a list of courses with only notes greater than 70, and located in classroom 23 (for example)? Is there a way to use the name of the entity instead of

SQL 'case when' in hibernate Criteria

孤街醉人 提交于 2020-01-15 12:35:09
问题 How can I tranform the following query to a hibernate Criteria? select pr_name, count(*) from (select (case when serv.type=xyz then serv.nameA else serv.nameB end) as pr_name from db.serv serv where serv.date is null group by pr_name; I have got the following to handle the rest (except for the case part) currentSession.createCriteria(StoredData.class) .setProjection(projectionList() .add(groupProperty("pr_name"), "pr_name") .add(rowCount(), "count")) .add(isNull("date")) .setResultTransformer