hql

HQL to SQL converter

旧时模样 提交于 2020-01-02 04:42:25
问题 Does anyone know how to convert NHibernate HQL to SQL Scripts? 回答1: Since HQL translation depends on your mappings and also runtime behaviour, I think it is unlikely there is a way to do so statically. You could run the HQL against a real database and capture the generated SQL either via a profiler for your specific rdbms or NHProf. 回答2: My old trainings. That was beta-version. Here it is! (hql2sql.jsp) <SCRIPT type="text/javascript"> <% org.hibernate.Session ThisSession = SessionFactory

Select from Table Valued Function nhibernate

浪子不回头ぞ 提交于 2020-01-02 04:35:12
问题 I need a little help on this. I'm trying to use a table-valued function in a select, but I got the error that this is not mapped. dbo.FnListEvnt is not mapped [from dbo.FnListEvnt(:dt, :id, :code) ] Function CREATE FUNCTION [dbo].[FnListEvnt] (@DT DATETIME, @ID INT, @CODE VARCHAR (4)) RETURNS @RESULTADO TABLE ( ID INT , DT_INIC DATETIME , DT_TMNO DATETIME , CD_EVNT VARCHAR (5) ) AS BEGIN Custom Dialect (this is defined in .config ) public class CustomFunctionsMsSql2008Dialect :

HQL select on embedded map

大憨熊 提交于 2020-01-02 03:51:26
问题 I want to use (searchable) localization in my models, and i came up with the following model: @Entity public class Category { ... @ElementCollection //key = language code (e.g. 'en') and value = localized label private Map<String, String> name; ... } What I want to do no is to query for categories which contain an caseinsensitive needle in a particular localization (e.g. with '%abc%' in their english name) I tried something like from Category where name.key = :locale and lower(name.value)

Are Hibernate named HQL queries (in annotations) optimised?

牧云@^-^@ 提交于 2020-01-02 03:28:08
问题 A new colleague has just suggested using named HQL queries in Hibernate with annotations (i.e. @NamedQuery) instead of embedding HQL in our XxxxRepository classes. What I'd like to know is whether using the annotation provides any advantage except for centralising queries? In particular, is there some performances gain, for instance because the query is only parsed once when the class is loaded rather than every time the Repository method is executed? 回答1: from Pro EJB 3 (Mike Keith): "...we

Hibernate 5.2 version -> A lot of Query methods deprecate?

纵饮孤独 提交于 2020-01-02 00:53:05
问题 I'm new to Hibernate. I'm trying to get a list of first name and last name of all administrators. There are two warnings in my following code. I already tried to search a lot online. 1) Query is a raw type. References to generic type Query should be parameterized. 2) The method list() from the type Query is deprecated. public List<Object> loadAllAdmins() { List<Object> allAdmins = new ArrayList<Object>(); try { HibernateUtil.beginTransaction(); Query q = currentSession.createQuery("SELECT

NHibernate HQL logic problem

走远了吗. 提交于 2020-01-01 16:33:11
问题 I'm trying to write an NHibernate HQL query that makes use of parenthesis in the where clause. However, the HQL parser seems to be ignoring my parenthesis, thus changing the meaning of my statement. Can anyone shed any light on the matter? The following HQL query: from WebUser u left join fetch u.WebUserProfile left join fetch u.CommunicationPreferences where (u.CommunicationPreferences.Email = 0 and u.SyncDate is not null) or u.DateDeleted is not null translates to: from WebUser webuser0_

Update several Columns in one Hibernate Query?

北慕城南 提交于 2020-01-01 08:02:54
问题 i have the Following HQL: String hql = "UPDATE Buchung as b " + "set STORNO = :Storno " + "where ID = :BuchungID"; Is it possible to Update more then one column in a HQL? For Example: String hql = "UPDATE Buchung as b " + "set STORNO = :Storno " + "set NAME = :Name " + ...... "where ID = :BuchungID"; I know how to do that in MSSQL but i dont know how to do that in Hibernate. 回答1: HQL is no different than SQL in this case. Just use comma to separate columns: String hql = "UPDATE Buchung as b

HQL: Fetch Join Collections from Eager Table

痴心易碎 提交于 2020-01-01 05:04:10
问题 I have four tables: RootNode // Will return multiple root nodes SubNode // Will return one sub node per root node SubNodeChildren1 // Will return multiple for each sub node SubNodeChildren2 // Will return multiple for each sub node and a similar entity structure: RootNode -> SubNode -> SubNodeChildren1 -> SubNodeChildren2 I need one query that will return all the RootNodes in the table with its SubNode and SubNode children initialized. The SubNode is eagerly fetched, but the SubNode children

Hibernate HQL delete with and

怎甘沉沦 提交于 2020-01-01 04:04:07
问题 Hibernate doesn't delete my row: public boolean deleteVote(Login user, int pid){ Session session = getSession(); try{ String hql = "delete from Vote where uid= :uid AND pid= :pid"; Query query = session.createQuery(hql); System.out.println(user.getUid() + " and pid: " + pid); query.setString("uid", user.getUid()); query.setInteger("pid", pid); System.out.println(query.executeUpdate()); }catch(Exception e){ Outprint: uid: 123 and pid: 1 Hibernate: delete from votes where uid=? and pid=? 1 The

JPA - Batch/Bulk Update - What is the better approach?

为君一笑 提交于 2020-01-01 03:19:13
问题 I found that JPA does not support the following Update: Update Person p set p.name = :name_1 where p.id = :id_1, p.name = :name_2 where p.id = :id_2, p.name = :name_3 where p.id = :id_3 .... // It could go on, depending on the size of the input. Could be in 100s So I have two options: Option 1: Query q = em.createQuery("Update Person p set p.name = :name where p.id = :id"); For ( int x=0; PersonsList.length; x++ ) { // add name and id parameters em.executeUpdate(); } Questions: Is this all