hql

Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?

梦想与她 提交于 2019-12-08 00:57:45
问题 I have a problem similar to this. But I want a does not contain functionality. Like I have a Post domain. A Post hasMany User. What I'd like to do, using createCriteria, is something like this: def c = Post.createCriteria() def l = c.list (max: maxVar) { notContains("users", thisUser) } I tried using ne But no luck. def l = c.list (max: maxVar) { users { ne('id', thisUser.id) } } To be clear, how can I get list of all the Post whose users field which is a collection does not contain thisUser

MYSQL case sensitive search (using hibernate) for utf8

百般思念 提交于 2019-12-08 00:40:46
问题 I have Login Table that have utf8 charset and utf8 collation when I want check user name and retrieve other information for this specific user name the hql query give me the same result with lowercase and uppercase. what should l do for my HQL query that work case sesitive I use Mysql 5 and java hibernarte this is my query: return queryManager.executeQueryUniqueResult("select b.login from BranchEntity b where b.userName = ?", username); 回答1: The easiest way is to change your column's

HQL right outer join

ⅰ亾dé卋堺 提交于 2019-12-07 19:51:30
问题 I am trying to perform right outer join in HQL. Query creation is done as mentioned below: Query query = this.sessionFactory .getCurrentSession() .createQuery( "select O.customer.id as id, O.customer.firstName as firstName, O.customer.lastName as lastName, O.customer.address as address, O.customer.city as city, count(O.id) as totalOrders from Order O right outer join O.customer group by O.customer.id"); SQL query on mysql is working fine, but the HQL query is returning the result for inner

QuerySyntaxException: Unable to locate class

情到浓时终转凉″ 提交于 2019-12-07 18:59:34
问题 I am using hql to generate an actual Java object of class JunctionManagementListDto. But I end up with the following exception on my console org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate class [JunctionManagementListDto] [SELECT new JunctionManagementListDto(c.siteId, c.name, c.ip, c.customer.id, zm.zone.name) FROM com.traff.hibernate.model.Controllers c, com.traff.hibernate.model.ZoneControllerMapping zm WHERE c.siteId = zm.controller.siteId ] at org.hibernate.hql

Cannot query entities using JOIN

不问归期 提交于 2019-12-07 17:55:34
I am trying to get my head around HQL and run it inside the Persistence window of IntelliJ IDEA. Here's the thing: I can run simple queries like these: hql> SELECT offer FROM OfferEntit offer; hql> SELECT offer FROM OfferEntit offer WHERE offer.id = 1L; but if I add something like a JOIN : hql> SELECT offer FROM OfferEntit offer JOIN offer.owner AS owner WHERE owner.id = 1L; I get an empty result. Always. No matter what I do. I have no idea why.. Also I checked whether those records exist - yes they do I do not get any error logs ASP Can you try with left join or join fetch SELECT offer FROM

HQL “Contains” statement howto?

浪子不回头ぞ 提交于 2019-12-07 17:31:38
问题 I have an entity that has a string property called Tags. I would like to query this entity based upon if a certain string is located in Tags property. So for example, I would have a function IList GetEntityByTag(string tag), this would return all Entity's that have the value of tag in their 'Tags' property. I tried going through the ICriteria approach... Expression.In(PropertyName, Value) but this is the exact opposite. I need something like Expression.In(Value, PropertyName). Perhaps IQuery

The data types datetime and time are incompatible in the greater than or equal to operator

江枫思渺然 提交于 2019-12-07 17:03:44
问题 I have a variable type time in a column of a table of the database. How can I compare this value in java with this field I mean can i use date, gregoriancalendar? I've tried adn I still have this message, please can someone give me an advice Date d2 = new Date(); // timestamp now Calendar cal = Calendar.getInstance(); // get calendar instance cal.setTime(d2); // set cal to date cal.set(Calendar.HOUR_OF_DAY, 10); // set hour to midnight cal.set(Calendar.MINUTE, 30); // set minute in hour cal

Hooking into Hibernate's query generation

喜夏-厌秋 提交于 2019-12-07 14:48:13
问题 I would like to implement virtual views with a preprocessor. A simple example: HQL before: FROM PublishedArticle a Effective HQL after: FROM Article a WHERE a.published = true Essentially I need a way to process queries before they get executed (instead of creating views on-the-fly which would have a high cost). 回答1: You can use a StatementInspector to completely rewrite the SQL to suit your needs. For further reading: How I can configure StatementInspector in Hibernate? 回答2: Couldn't you do

hql query to retrieve top n from each group

送分小仙女□ 提交于 2019-12-07 13:51:44
问题 i want to achieve the following in HQL - select top n from table1 where table1.id IN (some select sub query) i have found the setMaxResult(n) method, but it can only retrieve top n of the entire result.. but what i want to achieve is top n of each group... Thanks... 回答1: Here is JPQL you need: select a from Employee a where ( select count(*) from Employee b where a.department = b.department and a.salary <= b.salary ) <= 10 order by salary DESC 来源: https://stackoverflow.com/questions/4264528

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

自作多情 提交于 2019-12-07 12:35:30
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 = hibernateQuery.iterate(); return ""; }else{ //This finnaly return the result return query