criteria

deleting entries with JPA and subqueries

六月ゝ 毕业季﹏ 提交于 2019-12-23 05:17:59
问题 I just wrote an sql query : DELETE FROM basisgegevens.gm_persoonburgstaat pbs WHERE (pbs.ingangsdatum, pbs.id_persoon) in ( SELECT pbs2.ingangsdatum, pbs2.id_persoon FROM basisgegevens.gm_persoonburgstaat pbs2 WHERE pbs2.ingangsdatum = pbs.ingangsdatum AND pbs2.id_persoon = :persoonID AND pbs2.id_persoonburgerlijkestaat > pbs.id_persoonburgerlijkestaat); I need to rewrite it to JPQL, but am getting stuck with the subquery refrencing the outer query. public class PersoonBurgerlijkeStaatEntity

Hibernate Criteria: Is it possible to access a database view with criteria?

耗尽温柔 提交于 2019-12-23 05:13:29
问题 I have a criteria, which I'm trying to join to a database view. I'm wondering if it's possible and if so how to do it? As I understand, createAlias and createCriteria only join to child objects of the root criteria. I read about detachedCriteria , but it seems that those need to be created on database entities, which the view is not. The HQL equivalent would be something like this select * from root_criteria rc where rc.id in (select view.id from DATABASE_VW view where view.field is not null)

SQL statement, subquery count?

允我心安 提交于 2019-12-23 01:46:24
问题 I've got the following SQL tables Department |name|employees| Employee |name|gender|type|dead | |John|male |good|yes | |Mary|female|bad |no | |Joe |male |ugly|maybe| I would like to write a statement that returns | type | n of employees | n of male employees | n of departments | I've got SELECT e.type, count(e), count(d) FROM Department d JOIN d.employees e WHERE e.dead = maybe GROUP BY e.type That's missing the 'n of male employees', of course. I'm stuck here, since I'm not sure, where to

Doing Join query using CDBCriteria

 ̄綄美尐妖づ 提交于 2019-12-22 14:50:29
问题 I am trying to do a Join query using CDBCriteria in Yii framework. The issue is the join query works successfully but it does not display the columns from other tables. I am doing in the following way $criteria = new CDbCriteria; $criteria->order = 't.id desc'; $criteria->select = '*'; $criteria->join = ' INNER JOIN table2 INNER JOIN table3 INNER JOIN table4'; When i run this, I can see only the mail table1 columns displayed. Other columns are not shown. In my model class, I have the relation

JPA 2.0 CriteriaQuery on tables in @ManyToMany relationship

自闭症网瘾萝莉.ら 提交于 2019-12-22 12:56:13
问题 I have two entities in a @ManyToMany relationship. // Output has 4 other @ManyToOne relationships if that matters @Entity @Table public class Output { @Id public String address; @ManyToMany(targetEntity = Interval.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "output_has_interval", joinColumns = {@JoinColumn(name = "output_address", referencedColumnName = "address")}, inverseJoinColumns = {@JoinColumn(name = "interval_start", referencedColumnName = "start"),

JPA 2.0 CriteriaQuery on tables in @ManyToMany relationship

痴心易碎 提交于 2019-12-22 12:53:48
问题 I have two entities in a @ManyToMany relationship. // Output has 4 other @ManyToOne relationships if that matters @Entity @Table public class Output { @Id public String address; @ManyToMany(targetEntity = Interval.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinTable(name = "output_has_interval", joinColumns = {@JoinColumn(name = "output_address", referencedColumnName = "address")}, inverseJoinColumns = {@JoinColumn(name = "interval_start", referencedColumnName = "start"),

Constructor queries on a non-persistent entity unexpectedly fail to supply a Boolean parameter as a constructor argument

点点圈 提交于 2019-12-22 12:39:08
问题 There are two tables in MySQL database user_table feedback The relationship between them is intuitive - one to many from user_table to feedback . I need to fetch only a list of selected columns from these tables which are From feedback feedbackId (java.lang.Long) feedbackTitle (java.lang.String) feedbackDescription (String, decorated by @Lob ) feedbackDate (org.joda.time.DateTime) testimonial (java.lang.Boolean) From user_table userId (java.lang.Long) firstName (java.lang.String) These many

Hibernate Criteria - Exclude groupProperty from select

我只是一个虾纸丫 提交于 2019-12-22 10:27:45
问题 I would like to use a hibernate criteria object as a subquery on a second criteria, like this: DetachedCriteria latestStatusSubquery = DetachedCriteria.forClass(BatchStatus.class); latestStatusSubquery.setProjection(Projections.projectionList() .add( Projections.max("created"), "latestStatusDate") .add( Projections.groupProperty("batch.id")) ); DetachedCriteria batchCriteria = DetachedCriteria.forClass(BatchStatus.class).createAlias("batch", "batch"); batch.add( Property.forName( "created" )

Hibernate Criteria for Map key-value

孤街醉人 提交于 2019-12-22 09:27:06
问题 I have the following property in my hibernate entity: @ElementCollection(targetClass = String.class, fetch = FetchType.EAGER) @CollectionTable(name="FORMDATA", joinColumns = @JoinColumn(name="FORM_ID")) private Map<String, String> formData; I want to do a query with hibernate Criteria where I want to match a form with a given key-value pair, something like this: criteria.add(Restrictions.like("formdata.key", "%"+value+"%").ignoreCase()); where 'key' and 'value' are passed via method

Select … in equivalent in JPA2 criteria

情到浓时终转凉″ 提交于 2019-12-22 08:12:13
问题 Is there any way to perform a query like the following using JPA2 criteria APIs? select a from b where a in (1, 2, 3, 4) There's a way to do that using plain Hibernate, but we can't find anything like that in JPA2. 回答1: Yes JPA 2 Critera supports returning a specific field from a entity and using a where clause which includes an in clause. I have included an example below which takes a JPQL and converts it to a similar JPA 2 Criteria-based option. JPQL: select b.a from B b where a in (1, 2, 3