named-query

Named queries with nHibernate

I am having a great deal of trouble getting named queries to work with nHibernate. My latest problem is getting the error message "could not execute query" with no additional information. Are there any complete examples I can download from somewhere because all the tutorials and documentation examples provide code snippits but only tell ...

Using Unmapped Class with NHibernate Named Query

I'm using a custom named query with NHibernate which I want to return a collection of Person objects. The Person object is not mapped with an NHibernate mapping which means I'm getting the following exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. It's getting thrown w...

Doctrine Named Queries: Specifing limit on query call

Hey guys! Let's imagine something like this: class MyTable extends Doctrine_Table { public function construct() { $q = Doctrine_Query::create()->from('MyTable t') ->orderBy('t.creationDate DESC') ->limit(5); $this->addNamedQuery('top5', $q...

Using replace sql function in nHibernate named query

I am using Nhibernate 2.1.0 in my project. I have the an Item class with property Path and the following named query: <hibernate-mapping xmlns='urn:nhibernate-mapping-2.2'> <sql-query name='updateUNC'> <query-param name='oldUNC' type='String'/> <query-param name='newUNC' type='String'/> <![CDATA[ update Item s s...

Table Name Troubles With Hibernate Named Query

Hi all, I've got the following named query in Hibernate: <sql-query name="CreateLogTable"> CREATE TABLE IF NOT EXISTS :tableName ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `url` VARCHAR (750) NOT NULL, `query` VARCHAR (500), `ipaddress` VARCHAR (39), `datetime` DATETIME NOT NULL, `hits` MEDIUMINT UNSIGN...

NHibernate Fluent and named Queries

Hi there, I am using Nhibernate with fluent. Now I want to call some Stored procedure and use named Queries. I created some xml: <?xml version="1.0" encoding="utf-8"?> <hibernate-mapping> <sql-query name="CleanAppendicesHierarchies"> exec intf_CleanUpAppendixHierarchy </sql-query> </hibernate-mapping> FluentConfiguratio...

NHibernate named query and 2nd level cache

Hi all, I have the following mapping <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain.Core" namespace="Domain.Core"> <class name="Industry" table="INDUSTRY"> <cache usage="read-write" region="IndustryCache" include="all"/> <id name="Id" type="In...

JPA setParameter when dealing with "NOT IN (:param)"

Hi all, I'm trying to set a parameter in my query, for example: select * from Cars where Cars.color NOT IN (:color_params) And when I'm adding the parameter in my JavaClass is like: ... query.setParameter("color_params", "RED,BLUE"); ... And this is not working, is only working with only one parameter. I've tried with "'RED','BL...

Using a named query in a hbm with import class

In my MSSQL server I have a SQL view called AllFavourite. In order to load the data into my DTO class I have the following in my hbm.xml file... <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Domain.Model.Entities" assembly="Domain.Model"> <import class="AllFavourite"/>...

How do you decide in which entity classes to put JPA NamedQuery annotations?

Say I have a Customer - CustomerOrder one-to-many bi-directional relationship with the CustomerOrder holding the total value of each order. If I had a query to find the total value of all orders for a particular customer : select SUM(o.orderValue) from CustomerOrder o where o.customer = :customer Does it matter in which entity class ...

define named query in orm.xml with jpa and hibernate

Hello, I'm trying to put my named queries in my orm.xml (put in META-INF with persistence.xml) but my orm.xml seems to be ignored by hibernate/jpa. When I try to create my named query with em.createNamedQuery("myQuery"), it returns that it can't find this query. I use annotation and I would like to externalize my named queries in orm...

Optional parameters with named query in Hibernate?

Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate? I'm using a native SQL query, but the question is probably applicable to named HQL queries as well. I'm pretty sure the answer to this is 'no', but I haven'...

fluent nhibernate named-query without using hbm file for the map

I am needing to create a named-query, and use it with one of the maps, that i currently have defined as a fluent map. is it possible to continue using the fluent map, and be able to create the named-query dynamically in code? or, is switching to a hbm map the only option? ...

NotSupportedException on IQuery's Enumerable when using statelesssession

when trying to use the Enumerable method on a named query, with a Stateless session, as shown in the example at: http://www.nhforge.org/doc/nh/en/#batch-statelesssession i am seeing a NotSupportedException. the stack trace is as below: System.NotSupportedException: Specified method is not supported. at NHibernate.Impl.StatelessSession...

Spring 2.5 Hibernate 3.5 NamedQuery

I do not use HibernateTemplate, but work with getCurrentSession() in my DAO. I would like to know how to declare Hibernate named queries in a beans.xml file (I do not use hbm.xml). And maybe Spring has alternative means to declare Hibernate named queries? ...

Deleting orphans with JPA

I have a one-to-one relation where I use CascadeType.PERSIST. This has over time build up a huge amount of child records that has not been deleted, to such an extend that it is reflected in the performance. Now I wish to add some code that cleans up the database removing all the child records that are not referenced by a parent. At the m...

How to call Named Query

I wrote a named query in the entity class Voter NamedQuery(name = "Voter.findvoter", query = "SELECT count(*) FROM Voter v WHERE v.voterID = :voterID" and where v.password= : password), I want to call this named query and I also need to set voterID and password. Can you help me. Thank you ...

Hiberate variable schema name in SQL named query

Hi, Other than default schema, for some SQL queries I need to access a particular schema. The issue is that the name of that particular schema is different for different environments. After goggling I found that using this link I am able to specify the schema name in variable. If that’s true that I have following questions: Will that...

JPQL IN clause: Java-Arrays (or Lists, Sets...)?

I would like to load all objects that have a textual tag set to any of a small but arbitrary number of values from our database. The logical way to go about this in SQL would be to build an "IN" clause. JPQL allows for IN, but it seems to require me to specify every single parameter to IN directly (as in, "in (:in1, :in2, :in3)"). Is th...

Get list of named queries in NHibernate

I have a dozen or so named queries in my NHibernate project and I want to execute them against a test database in unit tests to make sure the syntax still matches the changing domain/database model. Currently I have a unit test for each named query where I get and execute the query, for example: IQuery query = session.GetNamedQuery("Ge...