criteria

Override lazy loading behavior 'lazy=false'

我怕爱的太早我们不能终老 提交于 2019-12-24 04:04:07
问题 I would like to override the default lazy loading behavior which is set in mappings as 'lazy=false'. Can't change it as many parts of existing application depend on this setting. After spent some hours on it I didn't find a solution so I'm asking here. How to do this? What I want to achieve is to fine tune my query to load only what is needed. This is what I've tried already: Using QueryOver api: var properties = session.QueryOver<Property>() .Fetch(prop => prop.Transactions).Eager .Fetch

Criteria, Subqueries, Group By and Having more

我的梦境 提交于 2019-12-24 02:22:06
问题 I have a product table with a relationship to color table a product can have many colors... exp: Product A: has red, green blue yellow. I wish to find the product which contain at least RED and GREEN. DetachedCriteria colorCrit = DetachedCriteria.forClass(Color.class); ProjectionList colorList = new Projections.projectionList(); colorList.add(Projections.groupProperty("productID")); colorList.add(Projections.rowCount(),"abc"); colorCrit.setProjection(colorList); colorCrit.add(Restrictions.eq(

Hibernate Criteria - how to limit join results to a single entity type?

假如想象 提交于 2019-12-23 20:30:16
问题 Ok, so the following query: SELECT O.*, P.* FROM ORDERS O, PRODUCT P WHERE O.ORDER_ID=P.ORDER_ID AND P.ID=’1234’; can be done with Criteria as follows: List ordersAndProducts = session.createCriteria(Order.class) .setFetchMode(“products”,FetchMode.JOIN) .add(Restrictions.eq(“id”,”1234”)) .list(); but here Criteria.list() returns a List<Object[]> where Object[0] is an Order and Object[1] is a Product for each element in the List. But how can I do the following SQL with Criteria: SELECT O.*

hibernate join two entity in different schema or session

一个人想着一个人 提交于 2019-12-23 19:36:21
问题 I have multiple schemas having their each table. ANIMAL.pet @Entity @Table(schema = "ANIMAL", name = "pet") @JsonIgnoreProperties(ignoreUnknown = true) public class Pet { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "idx") private Integer idx; @Column(name = "name") private String name; } HUMAN.person @Entity @Table(schema = "HUMAN", name = "person") @JsonIgnoreProperties(ignoreUnknown = true) public class Person { @Id @GeneratedValue(strategy = GenerationType

Is legacy Criteria API still recommended?

只愿长相守 提交于 2019-12-23 17:39:19
问题 My team has been using hibernate Criteria API for a long time under Hibernate 3.x. Recently, we want to upgrade Hibernate version to 5, but the Criteria API seemed not be recommended any more. But JPA looks like a totally different API which we don't want to risk. Should we keep using the old Criteria? 回答1: Well, the warning in the Version 5.0 Criteria Chapter is pretty darn big: Hibernate offers an older, legacy org.hibernate.Criteria API which should be considered deprecated. No feature

Nhibernate: restriction with sum of 2 columns

江枫思渺然 提交于 2019-12-23 17:08:05
问题 Can I create this sql query using HNibernate Criteria: Select * from Table1 where Column1 > (Column2 + Column3) All 3 columns are int32. Thanks 回答1: Well, after reading for the n-th time a question with this exact problem i decided to write an implementation that doesn't include writing SQL. You can check the implementation at http://savale.blogspot.com/2011/04/nhibernate-and-missing.html with which you can write: criteria.Add( Restrictions .GeProperty("Prop1", new

Use fewer columns on SQL query through Hibernate Projections on Entity with ManyToOne relation

邮差的信 提交于 2019-12-23 15:12:55
问题 I'm trying to build a smaller SQL, to avoid the "select * from A" that is being build by default for hibernate Criteria. If I use simple fields (no relation), through "Transformers", I have can manage to have this SQL: select description, weight from Dog; Hi, I have this Entity: @Entity public class Dog { Long id; String description; Double weight; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "person_id", nullable = false) Person owner; } @Entity public class Person { Long id; String

Hibernate Criteria Api Subqueries

空扰寡人 提交于 2019-12-23 14:46:12
问题 I am currently working on a project to transfer some legacy jdbc select statements over to using Hibernate and it's criteria api. The two relevant table columns and the SQL query looks like: -QUERIES- primaryId -QUERYDETAILS- primaryId linkedQueryId -> Foreign key references queries.primaryId value1 value2 select * from queries q where q.primaryId not in (SELECT qd.linkedQueryId FROM querydetails qd WHERE (qd.value1 LIKE 'PROMPT%' OR qd.value2 LIKE 'PROMPT%')); My entity relationships look

Hibernate Criteria Api Subqueries

狂风中的少年 提交于 2019-12-23 14:46:10
问题 I am currently working on a project to transfer some legacy jdbc select statements over to using Hibernate and it's criteria api. The two relevant table columns and the SQL query looks like: -QUERIES- primaryId -QUERYDETAILS- primaryId linkedQueryId -> Foreign key references queries.primaryId value1 value2 select * from queries q where q.primaryId not in (SELECT qd.linkedQueryId FROM querydetails qd WHERE (qd.value1 LIKE 'PROMPT%' OR qd.value2 LIKE 'PROMPT%')); My entity relationships look

Wrong fieldname in query with Criteria and Many-To-Many-Relation

Deadly 提交于 2019-12-23 12:26:04
问题 When I try to use a simple Criteria on a property with a different columnname in Many-To-Many-Relation, Doctrine uses the propertyname as the field and not the columnname. Person ORM Definition ... manyToMany: attributes: targetEntity: Attributes cascade: ['persist'] joinTable: name: person_attribute joinColumns: person_id: referencedColumnName: id inverseJoinColumns: attribute_id: referencedColumnName: id ... Attribute ORM Definition with differing columnname ... name: type: string nullable: