hql

Hibernate Query to fetch records on date ignoring timestamp

岁酱吖の 提交于 2019-12-06 07:04:08
I have a timestamp column tradedate in one of the DB(Oracle) tables. I am using hibernate as the persistence layer to fetch and store Data to DB. I have a requirement in which I need to query the DB on date. i.e From UI the user passes a date and I need to get the filtered data based on this date. If the tradedate column only has the date part my query returns the correct records The issue arises when the tradedate column is populated with a timestamp value ie(date + time). Then those values are not returned by the query. eg:say there are 10 records for 23rd Oct 2010 in DB 5 of them have the

Hibernate throws NullPointerException from HqlSqlWalker

拜拜、爱过 提交于 2019-12-06 06:51:29
问题 I have a web application, which has a search form and HQL is generated on the fly. Also, user can click on the column headers to sort items as needed. Some columns get ther data from very deep down the structure. I have this HQL, for example, which works flawlessly: SELECT s FROM Application s LEFT JOIN s.product AS product LEFT JOIN product.originCountry AS origin WHERE s.nr = ? ORDER BY origin.name ASC But this one fails miserably: SELECT s FROM Application s LEFT JOIN s.product AS product

Join Non ContentPart Table to ContentPart Table Using Orchard HQL API

大城市里の小女人 提交于 2019-12-06 06:31:17
问题 I am trying to perform a simple join between two different tables using the Orchard HQL API. The problem is that one of the tables is not a ContentPartTable. Is this possible?? Here is what it would look like in regular SQL: Select * From ItemPartRecord Join ItemRecord On ItemRecord.ItemId = ItemPartRecord.ItemId Where ItemRecord.Price Between 1000 and 10000 How exactly could I go about doing this? 回答1: If anyone is wondering how to do this: //Join the non content part table var

dynamically Search Query in HQL with optional Parameter?

♀尐吖头ヾ 提交于 2019-12-06 06:27:10
问题 i am developing an application in which i need search functionality, i want to write HQL query that dynamically create according to parameters. Currently i have 4 parameters, while searching all parameters are required or 1 or 2 or 3 parameters required according to how user want to searchs. public List<Plot> fetchSearchedPlots(int plotType, String plotSize, String min, String max) { Session session = sessionFactory.getCurrentSession(); List<Plot> searchedLists = new ArrayList<Plot>(); String

Round to 2 decimal places in hibernate query language

此生再无相见时 提交于 2019-12-06 06:26:56
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 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 use the floor function for rounding which is pretty generic and does not leave much room for different

QuerySyntaxException: Unable to locate class

末鹿安然 提交于 2019-12-06 06:26:21
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.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54) at org.hibernate.hql.internal.ast

NHibernate Polymorphic Query on a Collection

≡放荡痞女 提交于 2019-12-06 06:18:39
问题 I'm trying to write a query in NHibernate. I don't really care if I use the Criteria API or HQL, I just can't figure out how to write the query. Here's my model: public class LogEntry { public DateTime TimeCreated { get; set; } } public class Note : LogEntry { public string Content { get; set; } } public class Workflow { public IList<LogEntry> Log { get; set; } } I want the query to return all Workflows that which contain a Note with specific words in the Content of the note. In pseudo-SQL, I

HQL right outer join

*爱你&永不变心* 提交于 2019-12-06 06:11:41
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 join. SQL query is: select c.id, c.firstname, c.lastname, c.city, count(o.id) as total_order from orders

writing custom queries in Spring boot

柔情痞子 提交于 2019-12-06 05:34:57
问题 I have recently started using Spring boot, and have run into a bit of a problem. before, when i was just using Spring data with hibernate and JPA, I could create a hibernate.cfg.xml file that would give a bunch of configuration that could be passed to a config object and then ultimately create a SessionFactory object that would create a Session object that could be used to pass the query to hibernate: package util; import org.hibernate.SessionFactory; import org.hibernate.boot.registry

Map hibernate projections result to java POJO model

余生颓废 提交于 2019-12-06 05:22:26
问题 I've been using spring and hibernate for this past few weeks and I've always been learning something new there. Right now I've got a problem that I want to solve with Projections in Hibernate. Suppose there is a model Person and that model has many Car . The following are how the class definitions roughly gonna look like: public class Person implements java.io.Serializable { private Integer id; private String name; private List<Car> cars; private Integer minYear; // Transient private Integer