Questions tagged [named-query]

A Hibernate (and NHibernate) feature that allows for both HQL and SQL queries to be written in the mapping document, keyed by a name. The main advantage is that your query is now residing in the same place as the definition of your mappings, instead of in your Java/C#/VB.NET/... code.

521 questions
2
votes
1 answer

JPA NamedQuery Sub Query

I am knocking my head off on a Named Query. I use JPA.. What I would like to achieve is to select all articles with active flags, for a specifc last state (passed as a parameter). Here are my classes: Article (intId) ArticleState (An article may…
Charles Morin
  • 1,449
  • 4
  • 32
  • 50
2
votes
1 answer

java.lang.ClassCastException: [Ljava.lang.Object or LazyInitializationException

I write named query like this select tq from TestQuestion as tq inner join tq.question as q where tq.testQuestionIdentifer.versionId=(select …
Ray
  • 1,788
  • 7
  • 55
  • 92
2
votes
1 answer

jpa delete query error: unexpected token

I want to delete a list of items and I defined the following query for the Entity Email: @NamedQuery(name = Email.namedQueryDeleteOldEmails, query = "DELETE FROM Email e where e.creationDate <= :creationDate") When I execute it, I have the following…
aika
  • 73
  • 1
  • 1
  • 6
2
votes
2 answers

Named Query parameter in hour interval

I'm currently having trouble to execute this query using HQL. String queryString = "SELECT o FROM Orders o WHERE o.orderMade >= DATE_SUB(NOW(), INTERVAL :fetchTime HOUR)"; this will fetch the last orders from the last ":fetchTime" hours. The…
pulu
  • 495
  • 1
  • 7
  • 16
2
votes
0 answers

NamedQuery returns nothing

I have written a namedQuery in my Entity class as @NamedQuery(name="Place.findByPlaceCode", query="select p from Place p where p.Code = :placeCode") I execute the named query with the following : List result = getEntityManager() …
MindBrain
  • 7,398
  • 11
  • 54
  • 74
2
votes
1 answer

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:
Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61
2
votes
1 answer

NHibernate Named query with table per subclass

I have a project where we are using only named queries to access the database. Recently we have created new entities that we were planing to map following the table per Subclass pattern, so we created the mappings following the documentation and…
Drevak
  • 867
  • 3
  • 12
  • 26
2
votes
1 answer

Using a parameter to specify an expression in a named query

Can I use a query parameter to specify a table (object), column name, or expression in a named query? For example, I would like to use a single query that allows me to switch between selecting the whole object or just the count. select :param1 from…
OscarSan
  • 464
  • 8
  • 24
2
votes
2 answers

Doctrine Named Queries: Specifing limit on query call

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') …
Philippe Gerber
  • 17,457
  • 6
  • 45
  • 40
2
votes
1 answer

TOP clause applied in @NamedQuery

I have named query @NamedQuery(name="CustomerMarket.findByMarketId", query="SELECT DISTINCT c.marketid FROM CustomerMarket c WHERE c.marketid LIKE :mask") in my class CustomerMarket definition. I want to take first 1_000 of 350_000 results so I…
Jan Stanicek
  • 1,201
  • 1
  • 14
  • 30
1
vote
1 answer

Named query for dates (month and year)

I have the following domain class: class Car{ int hp Date registrationDate } Now what I'm trying to do is create a named query that enables me to do something like this: Car.getCarsByYear(2011) and Car.getCarsByYearMonth(2011,11) I'n not sure…
marko
  • 3,736
  • 6
  • 29
  • 46
1
vote
1 answer

Grails: namedQuery error: duplicate association path

Grails 1.3.7 I get this strange error when I try to invoke my named query. It is defined as follows; containsQuery { query -> or{ ilike("name", '%' + query + '%') ilike("description", '%' + query + '%') tokens{ ilike("token", '%' + query…
mkk
  • 7,583
  • 7
  • 46
  • 62
1
vote
1 answer

Mapping Exception: Unable to read XML when externalizing a named native query in JPA 2.0

I have some long queries (text wise) that I am trying to externalize into an orm.xml file for readability and maintainability purposes but I keep getting a mapping exception: Unable to read XML. This is what I have: persistence.xml in…
Viriato
  • 2,981
  • 7
  • 40
  • 54
1
vote
1 answer

JPA2 (Hibernate) how to query 2 tables (joined) but only need certains properties from 2nd table

I am using JPA2 with hibernate as provider in java ee6 environment. I have a one to many relationship and when getting all the rows for the one side to display in a JSF page, I want to display some of the many side's properties, ** but not all **…
user825402
  • 189
  • 3
  • 13
1
vote
1 answer

How to map a sql function as named query with Nhibernate's loquacious mapping?

I have replaced all my NHibernate xml mapping files by loquacious mappings (mapping by code). The only thing I can't figure out is if it is possible to define this named query using loquacious mappings:
TedOnTheNet
  • 1,082
  • 1
  • 8
  • 23