hql

Hibernate HQL: how to use a complex left join fetch

一曲冷凌霜 提交于 2019-12-09 10:56:45
问题 I want to add a left join on TASK table when the following condition occurs: LEFT JOIN FETCH PROMPT p on (t.id = p.task.id and p.applicationName in ('XXX') ) Here is my hql query: select distinct t from TASK t LEFT JOIN FETCH SERVER ser on t.id=ser.task_id LEFT JOIN FETCH APPLICATION app on ser.id=app.server_id LEFT JOIN FETCH PROMPT p on (t.id = p.task.id and p.applicationName in ('XXX')) where t.id=ser.task.id and ser.id=app.server and app.name in ('XXX') order by t.id I get the following

Ordering a join fetched collection in JPA using JPQL/HQL

烂漫一生 提交于 2019-12-09 09:40:12
问题 Given the below JPQL statement, how do I modify it so that the kittens in the resulting list are ordered by their age property? SELECT c FROM Cat c left join fetch c.kittens WHERE c.id = :id I've tried multiple approches but without any luck. This is esentially what I would like to do, but it doesn't work: SELECT c FROM Cat c left join fetch c.kittens k WHERE c.id = :id ORDER BY k.age 回答1: Hej, I don't think this is possible when applied using queries. But as far as I remember, you can use

Date Compare in HQL without timestamp

可紊 提交于 2019-12-09 08:59:17
问题 I have to compare two dates in hibernate hql query. I am using java.util.Date in my java bean and using timestamp as datatype in mysql database. select t from Task t where t.modifiedDate > t.endDate; Above query compares time with date. What should i do to compare date in above query without time. 回答1: See the Hibernate documentations for available date functions http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/queryhql.html In section 14.10 notice this line second(...), minute(...),

Hibernate is using wrong table name for order by expression with three level inheritance

混江龙づ霸主 提交于 2019-12-09 07:55:49
问题 In our project we have different user types presented by different classes. And we have a BaseEntity class as @MappedSuperclass. When we try to use user classes with InheritanceType.JOINED hibernate creates an sql that we think it is wrong. Base Entity : @MappedSuperclass public abstract class BaseEntity implements java.io.Serializable { private Integer id; private Date createdDate = new Date(); public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } @Temporal

Hibernate hql/criteria result contains collection

谁说我不能喝 提交于 2019-12-09 03:44:34
问题 I have two entities: public class Photo { Long id; String url; @ManyToOne @JoinColumn(name ="user_id") User user; // other fields and getters/setters } And second: public class User { Long id; @OneToMany(mappedBy = "user") private Collection<Photo> photos; // other fields and getters/setters } I am trying to get this DTO: public class UserDTO { Long id; List<String> photosUrls; } But I can't find the right solution. I wrote next criteria - find user with photos by login: getCurrentSession()

HQL to get elements that possess all items in a set

倾然丶 夕夏残阳落幕 提交于 2019-12-09 01:57:33
问题 Currently, I have an HQL query that returns all Members who possess ANY Award from a set of specified Awards: from Member m left join m.awards as a where a.name in ("Trophy","Ribbon"); What I now need is HQL that will return all Members who possess ALL Awards specified in the set of Awards. So, assuming this data: Joe has Trophy, Medal Sue has Trophy, Ribbon Tom has Trophy, Ribbon, Medal The query above would return Joe, Sue, and Tom because all three possess at least one of Trophy or Ribbon.

Nhibernate producing proxy despite HQL fetch

一曲冷凌霜 提交于 2019-12-09 01:54:21
问题 I have the following HQL statement: select distinct t from TaskEntity as inner join fetch t.Case as c inner join fetch c.Client as client inner join fetch c.Matter as matter However, despite Matter having a FETCH against it, it's still returning as a proxy. My mapping for this object is below References(x => x.Matter).Columns(new[] {"c_client","c_matter" }); I've tried using JOIN on this, but my issue I'm going from 1 to 2 columns, so it wouldn't accept the mapping. Any thoughts? Thanks, 回答1:

Where can I find a list of all HQL keywords?

 ̄綄美尐妖づ 提交于 2019-12-08 20:56:17
问题 Where can I find a list of all HQL keywords? 回答1: In the full Hibernate source download there's a grammar\hql.g file, which is the ANTLR language definition. You can view the latest version of this file from the official GitHub source repository here. In the tokens section you'll find all the tokens, including the keywords (they're the ones defined as strings, e.g. ALL="all" ). 回答2: Try this...not sure if it's complete or exact, but it may be, as it's a list of HQL tokens. 回答3: Here is the

How to get NHibernate.Type.IType from a Type?

橙三吉。 提交于 2019-12-08 18:43:52
问题 I try to do the following: hibQuery.SetParameter("MyParameter", valueObject, valueType); The only problem is that this method expects NHibernate.Type.IType in the third parameter, but valueType is of type Type . How could I convert this to IType? Thx for any tipps sl3dg3 回答1: Try the built-in NHibernateUtil.GetSerializable() method. It takes a CLR System.Type and returns the corresponding IType. More documentation: http://elliottjorgensen.com/nhibernate-api-ref/NHibernate/NHibernateUtil.html

Can I use hibernate query language for entities not mapped to a table?

自作多情 提交于 2019-12-08 16:55:10
问题 Following is the mySQL query that I am using to retrieve HolidayPackages for a given Hotel : SELECT pkg.idHolidayPackage, pkg.name FROM holidaypackage pkg INNER JOIN holidaypackagehotel hph ON pkg.idHolidayPackage = hph.idHolidayPackage INNER JOIN hotelroom hr ON hr.idHotelRoom = hph.idHotelRoom WHERE hr.idHotel = 1; I have POJOs with mapping for: HolidayPackage Hotel HotelRoom I don't have a POJO for HolidayPackageHotel . Is there any way to use Criteria API or HQL to execute the sql query