hql

How to configure intellij idea to use hibernate persistence tools and reading mapping files from external jar files

感情迁移 提交于 2019-12-24 09:29:50
问题 Assume that i have this below hibernate.cfg.xml file that contains data source configuration and path to jar files that contains .hbm.xml mappings: <?xml version='1.0' encoding='utf-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</property> <property name=

Save a Child for a existent Parent

梦想与她 提交于 2019-12-24 08:49:01
问题 I have a model with some inherits and it is using nhibernate to persisti on a Database. The nhibernate mapping with fluent nhibernate is working fine, but I have a scenario where I need to save a child for a existent parent. My model looks like this: public class Item { public long Id { get; set; } public string Name { get; set; } // other properties } public class ItemCommercial : Item { public decimal Value { get; set; } // other properties } In my Database, the respective tables are

Escaping a question mark character in a column name in NHibernate

点点圈 提交于 2019-12-24 06:37:55
问题 I have an entity with a property whose column name contains a question mark. How do I map the column name so that an HQL query will correctly generate SQL with the column name wrapped appropriately (i.e. [] for SQL Server) instead of substituting a parameter for the question mark? I have tried wrapping the column name in backticks or square brackets but this doesn't work. 回答1: Backticks work fine for me. Remember to use them only in the mapping file, not in the HQL: <property name="Data1"

Group by trunced date in JPA

限于喜欢 提交于 2019-12-24 03:18:58
问题 I need help! I need to build specification for SELECT date_trunc('day', start_time) FROM Example GROUP BY date_trunc('day', start_time) (PostgreSQL) I have code: CriteriaBuilder cb = entityManager.getCriteriaBuilder(); CriteriaQuery<Object[]> query = cb.createQuery(Object[].class); Root<Example> root = query.from(Example.class); Expression<Date> exp = cb.function("date_trunc", Date.class , cb.literal("day"), root.get("startTime")); List<Object[]> result = entityManager.createQuery(query

HQL Object Named Parameters

百般思念 提交于 2019-12-24 02:33:40
问题 I was wondering if it is possible to retrieve a specific column from an object named parameter in HQL. Example public class Product { private int id; private Supplier supplier; private String name; private String description; private double price; public Product() { super(); } public Product(String name, String description, double price) { super(); this.name = name; this.description = description; this.price = price; } public String getDescription() { return description; } public void

How to write Hibernate HQL query which remove all “grand children” elements?

徘徊边缘 提交于 2019-12-24 01:25:59
问题 I have schools, which contains groups, which contains students. I would like to remove all students from specific school. In SQL I can write the following query: DELETE FROM students1 WHERE students1.group_id IN (SELECT id FROM group1 WHERE group1.school_id = :school_id) How to transform this SQL query to Hibernate HQL? I use H2 database engine. (My real query is more complex and simple cascade deletion of school is not suitable for me). 回答1: The working script follows: DELETE FROM Student AS

NHibernate HQL: How to use the new object constructor with 'distinct'?

六眼飞鱼酱① 提交于 2019-12-24 00:25:58
问题 I need to use the HQL object constructor feature , e.g: select new SomeClass(i.Id, i.Name) from Item i... But I also need to use the distinct keyword , as there are joins further down in the query, e.g.: select distinct i.Id from Item i I have tried this: but it just causes an Antlr exception, so I assume it's invalid syntax: select new SomeClass(distinct i.Id, i.Name) from Item i Is this possible? 回答1: Ah, it looks like this works: select distinct new SomeClass(i.Id, i.Name) from Item i...

Nhibernate CreateSQLQuery Stored Procedure result to non mapped class

青春壹個敷衍的年華 提交于 2019-12-23 19:18:32
问题 In my application I want to get data from a stored procedured where the table is not mapped in the application. In this stored procedure I added aliases to the column names which respond to the properties in my class. HQL: return Session.CreateSQLQuery("exec PER_PrikklokSaldi :IDPers :jaar :maand") .AddScalar("Description", NHibernateUtil.String) .AddScalar("StartSaldo", NHibernateUtil.Int32) .AddScalar("Plus", NHibernateUtil.Int32) .AddScalar("Minus", NHibernateUtil.Int32) .AddScalar(

Hibernate HQL: pass pair values as parameters in IN clause

白昼怎懂夜的黑 提交于 2019-12-23 18:27:57
问题 I am facing a problem: how to pass parameters to HQL for pair values in query with IN clause like - select id, name from ABC where (id, reg_date) in ('x', 'y') . And the parameters are of different data types string (id) and reg_date (date). Now, in HQL I can write: hql = "select id, Name from ABC where (id, date) in (:listparam1)" hibernateTemplate.findbynamedparam(hql, "listparam1", values). Problem: how to pass a list of id and date pairs in HQL? Both parameters are of different data types

java.lang.ClassCastException: org.hibernate.hql.ast.tree.SqlNode cannot be cast to org.hibernate.hql.ast.tree.FromReferenceNode

半腔热情 提交于 2019-12-23 17:06:02
问题 Im trying to update a record with a HQL query but I am getting a CastException . If anyone could help me out I would really appreciate it. I have checked the Internet for a while now but I cant find any information on this. Please let me know if you have more information on this exception. The full error message its returning: Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: org.hibernate.hql.ast.tree.SqlNode cannot be cast to org.hibernate.hql.ast.tree.FromReferenceNode