hql

No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode HQL

匿名 (未验证) 提交于 2019-12-03 02:51:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the HQL where I trying to get artifacts that have no classification (when active is 0) artifacts = Artifact.findAll("FROM Artifact WHERE id NOT IN ( SELECT artifact_id FROM Classification WHERE active = 1) AND document_id = :docid",[docid:document.id], [max:limit, offset:startIndex]); Whenever I run I get the error java.lang.IllegalStateException: No data type for node: org.hibernate.hql.internal.ast.tree.IdentNode \-[IDENT] IdentNode: 'artifact_id' {originalText=artifact_id} Classificaiton definition: class Classification { public

HQL ERROR: Path expected for join

匿名 (未验证) 提交于 2019-12-03 02:14:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I keep trying variations of this query and can't seem to make this happen. I've also referenced this post: Path Expected for Join! Nhibernate Error and can't seem to apply the same logic to my query. My User object has a UserGroup collection. I understand that the query needs to reference entities within the object, but from what I'm seeing I am... @NamedQuery( name = "User.findByGroupId", query = "SELECT u FROM UserGroup ug " + "INNER JOIN User u WHERE ug.group_id = :groupId ORDER BY u.lastname" ) 回答1: select u from UserGroup ug inner join

Nhibernate HQL where IN query

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Im trying to return a SimpleQuery list that queries a single table and uses IN. I can get this to work using return new List ( ActiveRecordMediator .FindAll(Expression.In("ServiceId", ids)) ); However this is really really really slow. So id like to do something like this SimpleQuery query = new SimpleQuery (@"from Job as j where ? in (j.ServiceId)", ids); return new List (query.Execute()); However I cant get the SimpleQuery to work. I cant find any documentation covering this and was hoping someone out there would be able to help. Thanks

HQL order by within a collection

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have 2 entities: car and wheels (oneToMany) and I want to retrieve my car, with all the wheels and (this is the tricky part) ordered by wheels.location. The below code throws an exception with the message "illegal attempt to dereference collection." Select c from Car LEFT JOIN FETCH c.wheels order by c.wheels.location Any idea how to do this and if this is possible in HQL? 回答1: SELECT DISTINCT c FROM Car LEFT JOIN FETCH c.wheels AS wheels ORDER BY wheels.location 回答2: I think that you have to set the Car alias in the from request: SELECT

Hibernate returns null hql in query with @ManyToOne

匿名 (未验证) 提交于 2019-12-03 01:46:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: First I apologize if my question seems a bit amateurish, but my knowledge with hibernate / jpa and mysql are somewhat limited. Well, I have the following entity: User Entity @Entity @Table(name = "user") public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id_user") private Long idUser; @Column(nullable = false) private String name; @Column(nullable = false) private String email; @ManyToOne(optional = true, fetch = FetchType.EAGER) @JoinColumn(name = "level", referencedColumnName = "id_level", nullable =

org.hibernate.hql Errors in HQL subqueries

匿名 (未验证) 提交于 2019-12-03 01:44:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a Table which has meta-data of the files . The Table has columns id, path, originalSize, lastModified and info_id ; id, path, lastModified, originalSize, infoid 01, A.txt, 25/10/2014, 25, 0 02, A.txt, 26/10/2014, 30, 0 03, B.txt, 25/10/2014, 40, 0 04, B.txt, 27/10/2014, 50, 0 05, C.txt, 25/10/2014, 10, 0 06, C.txt, 26/10/2014, 20, 0 07, D.txt, 25/10/2014, 5, 0 08, D.txt, 27/10/2014, 10, 0 I need a sum on the originalSize column where the path is one of some given list of paths and the lastModified is maximum of all the rows with that

Nhibernate HQL Subselect queries

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following SQL query: select c.id from (select id from customers) c This query has no practical value - I simplified it greatly for the purpose of this post. My question: is it possible have a subquery in the from clause using HQL. If not, can I perhaps query the customers first, kinda like a temp table in sql, and then use the result as the source of the next query? thanks 回答1: Yes, it's possible. The query above can be written in HQL as: select Id from Customer where Id in (select Id from Customer) 回答2: I've run into this issue

Difference between INNER JOIN and LEFT SEMI JOIN

穿精又带淫゛_ 提交于 2019-12-03 01:08:08
问题 What is the difference between an INNER JOIN and LEFT SEMI JOIN ? In the scenario below, why am I getting two different results? The INNER JOIN result set is a lot larger. Can someone explain? I am trying to get the names within table_1 that only appear in table_2 . SELECT name FROM table_1 a INNER JOIN table_2 b ON a.name=b.name SELECT name FROM table_1 a LEFT SEMI JOIN table_2 b ON (a.name=b.name) 回答1: An INNER JOIN returns the columns from both tables. A LEFT SEMI JOIN only returns the

第六节 使用HQL和QBC查询数据

匿名 (未验证) 提交于 2019-12-03 00:34:01
简单查询 from 实体类名 as关键字可以省略 查询所有学生,并按照id升序排列 from Student as stu order by stu.id asc 属性查询 查询学生的姓名和年龄 select stu.name,stu.age from Student as stu 聚集函数 select count(stu) from Student stu select ave(stu.score) from Student stu 分组查询 select employee.dept.name,count(*) from Employee as employee group by employee.dept 动态查询 将结果封装成对象 select new Person(stu.name,stu.age) from Student stu; 在项目中需要有 Person 类,同时 Person 类中有 Person(String name,Integer age) 构造函数 分页查询 public void pagedSearch ( int pageIndex, int pageSize){ String hql= "from Student" ; Query query = session.createQuery(hql); int startIndex =

对HQL常用检索方法的一些总结

匿名 (未验证) 提交于 2019-12-03 00:25:02
该博客主要为日后查看关于HQL查询方法提供便利而写。 HQL查询有投影查询,条件查询,指定别名,动态实例和分页。由于后三种使用不熟我就不重点回顾,所以本文重点说前两种。 代码红色部分为查询具体代码。 1.投影查询: 目的是为了只通过查询部分属性来查询对象,从而节省查询性能。 查询方法是使用关键字select,并在其后加上需要查询的属性,然后就是from关键字和实体类名。 下面举例说明,在HQLTest类中,编写portionQueryTest()方法,只查询customer表中的name和age信息,代码如下所示。 @Test public void portionQueryTest(){ Configurtion config=new Configuration().configure(); SessionFactory sessionFactory=config.buildSessionFactory(); Session session=sessionFactory.openSesssion(); Transaction t=session.beginTransaction(); String hql="select c.name,c.age from Customer as c"; Query query=session.createQuery(hql); List