hql

org.hibernate.Query .iterate() VS .getResultList() query generation

流过昼夜 提交于 2019-12-23 02:32:22
问题 I am using org.hibernate.Query Api to query for result. But i ran into strange problem. This is suppose my query select DISTINCT abc FROM ABC abc where ORDER BY abc.name ASC . I have tested this with Oracle database . let say i have code as below public static List executeQuery(EntityManager em, Query query) { org.hibernate.Query hibernateQuery = query.unwrap(org.hibernate.Query.class); // this piece of code is used to fetch data from cache based on id if(EntityCacheable){ Iterator<Entity> it

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

Hibernate HQL query does not update the Lucene Index

断了今生、忘了曾经 提交于 2019-12-22 12:18:10
问题 I am using Hibernate 3.6.3 Final and Hibernate Search 3.4.1. I wrote an HQL delete query. The objects are deleted from the database but they are not removed from the Lucene Index after the transaction completes. Here is the query: Session session = factory.getCurrentSession(); Query q = session.createQuery("delete from Charges cg where cg.id in (:charges)"); q.setParameterList("charges", chargeIds); int result = q.executeUpdate();` What am I missing? What do I need to do to solve issue? I

Round to 2 decimal places in hibernate query language

跟風遠走 提交于 2019-12-22 11:29:00
问题 Hi can someone help me how to round to 2 decimal places in hql? I can't find anything online. Below is my query: Select p.amount as amt,p.desc from pay p, register r where r.type=?1 and r.code=?2; I would be glad if someone can help on this. Technology used: hibernate, spring, java, primefaces 4.0, oracle database 回答1: I have struggled with this a lot an finally found the following solution: If you want to be more DB independent and specifically want to support Postgres or Oracle DB you can

Spring MVC 3.1.2 + Jackson 2: LazyInitializationException when lazily initialize a collection - no session or session was closed

走远了吗. 提交于 2019-12-22 09:55:47
问题 I'm getting crazy with an error that I'm having using Spring MVC 3.1.2 and Jackson 2. I have the following model Class: @Entity @Table(name = "USER") @JsonIgnoreProperties(ignoreUnknown=true) public class User implements Serializable { @Id @SequenceGenerator(name = "USER_ID", sequenceName = "USER_ID_SEQ", allocationSize = 1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "USER_ID") private Long id; @Column(length = 50, nullable = false) private String firstName; @Column

HQL (Hibernate) how to check if a list of elements is a subset of another list?

橙三吉。 提交于 2019-12-22 08:22:34
问题 I am having tough time creating a HQL query that checks if a list of records 'a' of table 'X' is included within another list 'b' of the same table 'X'. Here is an example i am using: select r from Role r where ( select p from Permission p where p.name = 'test') in elements(r.permissions) Now this query is just as an example, to clarify a bit, each role has 1 or more permission. Now here's what happen, if the the subselect (permission p) returns 1 row, all work fine. But if more are selected,

How to avoid old style outer join (+) in Hibernate?

吃可爱长大的小学妹 提交于 2019-12-22 05:31:53
问题 I've wrote HQL query like this: SELECT a FROM A a LEFT JOIN a.b where ... Hibernate generate sql query like this: SELECT a FROM A a LEFT JOIN a.b where a.b_id = b.id(+) But when I write something like this: SELECT a FROM where a.b.id > 5 It generate SQL: SELECT a.* FROM A b cross join B b where b.id > 5 So when I combine this approaches I recieve Oracle ERROR: SQL Error: 25156, SQLState: 99999 ORA-25156: old style outer join (+) cannot be used with ANSI joins So is there way to say to

Join fetch: “query specified join fetching, but the owner of the fetched association was not present in the select list”

ⅰ亾dé卋堺 提交于 2019-12-22 05:22:30
问题 I have a following code: public class ValueDAO implements BusinessObject<Long> { private Long id; private String code; private ClassDAO classDAO ; .... } public List<String> getCodesByCodeClass(Long classId) { String select = "select distinct val.code from ValueDAO val left " + "join fetch val.classDAO "; String where = "where val.classDAO.id = ? order by val.code"; return getHibernateTemplate().find(select + where, classId); } It raises an exception: org.hibernate.QueryException: query

How to lazy load a one-to-one composition via hql

≯℡__Kan透↙ 提交于 2019-12-22 02:06:06
问题 If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B. The mapping is as follows: <class name="EntityA" table="TABLE_A" mutable="true" lazy="true"> <id name="idA" type="long" column="pk_a" unsaved-value="null"> <generator class="sequence"> <param name="sequence">pk_a_seq</param> </generator> </id> <one-to-one name="propertyB" class="EntityB" property-ref="propertyA" constrained="true" outer-join="false"/> </class> and <class name="EntityB" table="TABLE_B" mutable=

How to lazy load a one-to-one composition via hql

被刻印的时光 ゝ 提交于 2019-12-22 02:05:22
问题 If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B. The mapping is as follows: <class name="EntityA" table="TABLE_A" mutable="true" lazy="true"> <id name="idA" type="long" column="pk_a" unsaved-value="null"> <generator class="sequence"> <param name="sequence">pk_a_seq</param> </generator> </id> <one-to-one name="propertyB" class="EntityB" property-ref="propertyA" constrained="true" outer-join="false"/> </class> and <class name="EntityB" table="TABLE_B" mutable=