hql

hql query : sum of two sub-select

隐身守侯 提交于 2019-12-12 04:10:02
问题 what's wrong with this HQL query : select ( ( select sum(base)/8 FROM com.agitech.erp.model.rhp.RhpEmployeRubric where ...) + ( select sum(base)/8 FROM com.agitech.erp.model.rhp.RhpEmployeRubric where ...) ) Having the exception : unexpected end of subtree i also try select ( select sum(base)/8 FROM RhpEmployeRubric where ...) as sum1, ( select sum(base)/8 FROM RhpEmployeRubric where ...) as sum2 same exception ! 来源: https://stackoverflow.com/questions/23303315/hql-query-sum-of-two-sub-select

HQL : filtering query only 2 month before

此生再无相见时 提交于 2019-12-12 04:09:48
问题 i want to ask, how to convert this postgres query to HQL : select * from transactions where trans_time >= date(now() - 60 * interval '1 day') how to convert that query(in bold type) to hql? Thanks 回答1: Calendar minDate = Calendar.getInstance(); minDate.add(Calendar.DATE, -60); String hql = "select t from Transaction t where t.transactionTime >= :minDate"; List<Transaction> result = session.createQuery(hql) .setTimestamp("minDate", cal.getTime()) .list(); 来源: https://stackoverflow.com

MySQL table order by one column when other column has a particular value

感情迁移 提交于 2019-12-12 04:08:17
问题 I have two mysql tables record_items , property_values with the following structure. table : property_values (column REC is foreign key to record_items) id(PK)|REC(FK)| property | value| 1 | 1 | name | A | 2 | 1 | age | 10 | 3 | 2 | name | B | 4 | 3 | name | C | 5 | 3 | age | 9 | table: record_items id(PK) |col1|col2 |col3| 1 | v11| v12 | v13| 2 | v21| v22 | v23| 3 | v31| v32 | v33| 4 | v41| v42 | v43| 5 | v51| v52 | v53| record_items table contains only basic information about the record,

select multiple new() object in hql query

夙愿已清 提交于 2019-12-12 03:47:06
问题 I have a question about hql language. I'm trying to generate DTO's via hql syntax on my WCF REST application. I have a problem with the second query. What is wrong with it? Is there any other way to reach the same result? This works good. session.CreateQuery(@"select new EntityTypeDTO(t.ID, t.Title, assc.ID) from crmEntityType t left outer join t.Association as assc").List<EntityTypeDTO>(); This does not work. session.CreateQuery(@"select new EntityTypeDTO(t.ID, t.Title, assc.ID, new

NOT IN Clause in HQL

谁说我不能喝 提交于 2019-12-12 03:13:49
问题 How to write this query in HQL: select * from Employee where Emp_Code NOT IN (select Emp_Code from EmployeeAllocation); I was unable to find any solution for this on google. I dont know how to write NOT IN clause in HQL The result should must be fetched to a List. Like this: List<String> lst = query.list(); 回答1: I think you can do it like, As you haven't provided any information about the table structure, otherwise I would have suggested you some better query. But here in the below shown

Query dsl returning duplicate records on @one to many association(leftJoin vs leftJoin.fetch vs fetchAll)

爷,独闯天下 提交于 2019-12-12 02:50:37
问题 Here is my scenario: i have person entity which looks like below. @Entity public class Person{ @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) private Set<PhoneNumber> phoneNumbers = new HashSet<>(0); @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "AGENCY_ID") private Agency agency; I am unable to retrieve correct data,when i query for persons. Problems i have : 1. duplicate records. 2. person with no agency not returning . 3. Bad performance Here is what i tried, and see

Cannot create Typed Query for query with more than one return using request result type

点点圈 提交于 2019-12-12 02:23:16
问题 I'm trying to bind oracle result list to a summary list. But my summary list has 3 classes defined as entities of DB I have three entity classes A, B, C Summary.class { @Autowired private A a; @Autowired private B b; @Autowired private C c; //getters and setters } @Enity class A{ Fields 1..n ; } // same goes for other classes definition I get the results with following query, but the results cannot be cast to the Summary object List<Summary> summaryList = entityManager.createQuery("from A a,

HQL: replace on elements()

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 01:54:43
问题 I have the following HQL-Query: from Paperboy as paperboy where replace(replace(paperboy._mobile, ' ', ''), '/', '') = :nr or replace(replace(paperboy._phone, ' ', ''), '/', '') = :nr or :nr in elements(paperboy._additionalPhoneNumbers) Now the problem is, that I also have to replace spaces and slashs in the _additionalPhoneNumbers. Is this possible via HQL? I tried things like from Paperboy as paperboy where replace(replace(paperboy._mobile, ' ', ''), '/', '') = :nr or replace(replace

Nested query with HQL / Hibernate

独自空忆成欢 提交于 2019-12-12 00:36:52
问题 For what I have read, in some cases it is not possible to nest subqueries in HQL / Hibernate. Let's say that I have a table of articles with a price, that belong to a group. We want to add them all, but we can only add up to a limit per group of articles. Actually, the table is denormalized, so that we already have the maximum amount for the group in the article table. So the SQL would be as simple as : SELECT SUM(case when max_amount is null then price when price<max_amount then price else

JPQL - Update with Multiple where conditions

泄露秘密 提交于 2019-12-12 00:23:44
问题 Does JPQL support the following Update? Update Person p set p.name = :name_1 where p.id = :id_1, p.name = :name_2 where p.id = :id_2, p.name = :name_3 where p.id = :id_3 If not, are there any alternatives? I tried it myself. But createQuery returned null. 回答1: Case expression is supported in JPA 2.0. I have provided pseudo-code, can make modifications accordingly. You can try below JPQL query using CASE . Update Person p set p.name = CASE WHEN (p.id = :id1) THEN :name_1 WHEN (p.id = :id2)