named-query

define named query in orm.xml with jpa and hibernate

一笑奈何 提交于 2019-11-27 20:08:56
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.xml (only that). Here is my persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java

Using Unmapped Class with NHibernate Named Query

若如初见. 提交于 2019-11-27 07:13:44
问题 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 when the Session gets created because it can't find the class name when it calls NHibernate.Cfg.Mappings.GetClass(String className). This is all fairly understandable

Optional parameters with named query in Hibernate?

不打扰是莪最后的温柔 提交于 2019-11-27 04:24:58
问题 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't found the definitive answer in the documentation yet. 回答1: AFAIK, there is no such thing so you'll have to write a dynamic query for this. Maybe have a look

define named query in orm.xml with jpa and hibernate

时光总嘲笑我的痴心妄想 提交于 2019-11-26 22:53:54
问题 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.xml (only that). Here is my persistence.xml: <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3

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

拈花ヽ惹草 提交于 2019-11-26 19:33:12
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 there some way to specify an array, or a list (or some other container) that should be unrolled to the values of an IN clause? Pascal Thivent I'm not sure for JPA 1.0 but you can pass a Collection in JPA 2.0: String qlString = "select item from Item item where