hql

HQL query using a date column

♀尐吖头ヾ 提交于 2019-12-11 23:38:59
问题 I am trying to create a query that will return a List of Person objects based on if the createDate field falls after a passed string that represents a date. My createDate fields is mapped like this in my Person class @Basic(optional = false) @Column(name = "CREATE_DATE") @Temporal(TemporalType.DATE) private Date createDate; My function to find all person results after a date looks like this. public List<Person> searchDate(String startDate) { Session session = getSessionFactory().openSession()

Hql query using dot´s in the response parameters

▼魔方 西西 提交于 2019-12-11 21:05:12
问题 I am accesing to the database using a Dto with some entities and I want to improve the request without modifing my dto and removing the fetch so hibernate don´t return all the data from all the entities (hibernate is set to lazy), I tried with the next, but it´s not working: StringBuilder hql = new StringBuilder(); hql.append(" select d.id as id, ce.cod as clasification.cod "); hql.append(" from Document d"); hql.append(" join d.clasificacionEntity ce"); The working hql request: StringBuilder

HQL double join query with one to many relationship

荒凉一梦 提交于 2019-12-11 18:52:24
问题 This HQL query has been driving me up a wall, and I hope someone can help me out. Here is my data model: public class Record { private int id; private String name; private Set<RecordFieldData> recordFieldData; } public class RecordFieldData { private int id; private String data; private Record record; private RecordTypeField type; private User relatedUser; } public class RecordTypeField { private int id; private String dataType; } Here is some data: Record ------------------------------------

org.hibernate.hql Errors in HQL subqueries

僤鯓⒐⒋嵵緔 提交于 2019-12-11 18:12:33
问题 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

NetBeans HQL editor wrong translation to SQL

£可爱£侵袭症+ 提交于 2019-12-11 17:33:01
问题 I'm trying to access a MySQL database from a Java webservice. I'm using the NetBeans IDE and am following the tutorial Using Hibernate in a Web Application Now when I try to test the HQL query: from calls I get: org.hibernate.exception.SQLGrammarException: could not execute query blablabla Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

Hibernate Criteria: How to create a query for many search fields?

蓝咒 提交于 2019-12-11 16:36:23
问题 I need to fetch details from DB if any of the fields are entered, the fields are as below Date Code Action Status UserName Application. Kindly help me as any of the fields can be entered and not necessarily all values need to entered. Thanks & Regards, Jafer 回答1: public List searchAccommodation(Date startDate, Date endDate, Country country, AccommodationType type, Integer capacity) Criteria criteria = session.createCriteria(Accommodation.class); if (startDate != null) { criteria.add

Conversion of below criteria into HQL

无人久伴 提交于 2019-12-11 16:24:35
问题 I have the following criteria please advise how can I convert the below criteria into HQL , as I want to use HQL public List<tttBook> findtooks() { List<tttBook> tooks =null; Criteria criteria = session.createCriteria(tttBook.class); ProjectionList proList = Projections.projectionList(); proList.add(Projections.property("Id")); proList.add(Projections.property("longName")); tooks = criteria.list(); return tooks; } also please let me know in this above criteria what is wrong since right now it

org.hibernate.hql.ast.QuerySyntaxException

扶醉桌前 提交于 2019-12-11 16:05:08
问题 i get this exception when i was running an application please give me a solution in my mapping file like as follows: <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="mobilserv.bo.SalesanalyzerBean" table="sales_analyzer"> <id name="id" access="field" type="long" column="ID"> <generator class="native" /> </id> <property name="name" access="field"

How to check NULL or not valid in HQL query

孤街浪徒 提交于 2019-12-11 15:24:56
问题 I have two different table artifact and classification. I want to retrieve list of artifacts who dont have classification. The classification table contains ID(PK), Artifact_Id(foreign key), Active(0/1) while the artifact table contains ID(PK),Name. Each artifact can have many classification. I want to return a list of artifacts when there is no classification for it (i.e. classification does not contain that artifact or when the artifact has classification but all of instances are not active

HQL Subqueries in joins

与世无争的帅哥 提交于 2019-12-11 14:43:01
问题 I have a class Order that contains a set of OrderSection's that itself contains a set of OrderItem's. In SQL, one can use a SELECT statement in a JOIN clause as done in the following query: SELECT o.id, o.amount, sum(s.quantity*s.price), sum(s.quantity*i.price) FROM orders AS o JOIN ordersections AS s ON s.order_id=o.id JOIN (SELECT section_id, sum(quantity*price) AS price FROM orderitems GROUP BY section_id) AS i ON i.section_id=s.id GROUP BY o.id, o.amount Would it be possible to express