named-query

JPA named query match a list of tuples in IN clause

≯℡__Kan透↙ 提交于 2019-12-10 03:34:00
问题 spring data jpa 1.4.3 with Oracle 11g. I have an entity like this: class LinkRecord { String value; int linkType; ... } I am using (value, linkType) as a composite index. For a given list of (v, t) tuples, we need to select all the records in the DB so that value = v, linkType = t. Basically, I want to build this query: SELECT * FROM LINK_RECORD WHERE (VALUE, LINK_TYPE) IN (('value1', 0), ('value2', 25), ...) where the list in the IN clause is passed in as a param. Since we're working with a

@NamedNativeQuery with @SqlResultSetMapping for non-entity

荒凉一梦 提交于 2019-12-09 16:14:07
问题 I have been using this post as an example. I have a complex join query (simplified here). It returns a subset of values from two tables (and a derived column using CASE). I don't think I need to use an entity annotation because the object returned from my result set is not an actual table in my schema. My non-entity object that I want to hold results from my join query: @SqlResultSetMapping( name="myMapping", classes={ @ConstructorResult( targetClass=CarLimitDelta.class, columns={

How can I use JPQL in a NamedQuery to create an entity having a calculated transient attribute?

喜你入骨 提交于 2019-12-08 11:33:38
问题 I have an SQL statement: SELECT x.SPEED, (6371 * acos(cos(radians(16.65555))) * cos(radians(LATITUDE)) * cos(radians(LONGITUDE) - radians(54.55555)) + sin(radians(16.65555)) * sin(radians(LATITUDE))) AS dist FROM MY_TABLE x HAVING dist <= 50 ORDER BY dist How can I put this into a NamedQuery within a Java entity class in a way that the calculated value is set into this entity as a transient attribute called distance ? For the time being I have tried this: SELECT vsle, (:distance_unit * FUNC(

Can we define all the Named Queries at one place like some property file instead of writing in the entity class

时光毁灭记忆、已成空白 提交于 2019-12-07 06:15:30
问题 How to Define All Named Queries in One place (like class) instead of writing the NamedQuery in top of Entity class. For Example i have a base class. In this class i can define all named queries. Base.java @Entity @NamedQueries({ @NamedQuery(name="Student.findAll", query="SELECT s FROM Student s"), @NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")}) class Base { } Assume now i have two entities like Student and Employee. Now i want to access the Named query from Base class

hibernate query returns only first character of string

梦想的初衷 提交于 2019-12-06 04:34:35
问题 When I run a query like this in oracle 10g using sqldeveloper, it runs fine. select 'Canada' as "country", emp.name as "name" from emp. Gives me the name and country. When I run it in hibernate as a named query, I get only 'C' instead of 'Canada' for "country". Why is this so? 回答1: select cast('Canada' as varchar2(100)) as "country", emp.name as "name" from emp. 来源: https://stackoverflow.com/questions/5343355/hibernate-query-returns-only-first-character-of-string

How to load a Hibernate 'xxx.hbm.cfg' file in a JPA 2.0 project?

非 Y 不嫁゛ 提交于 2019-12-06 03:47:21
问题 I have just started a Spring Roo application with Hibernate as a JPA2.0 provider. I am using the jars as follows: hibernate-core-3.6.4.Final.jar hibernate-commons-annotations-3.2.0.jar hibernate-entitymanager-3.6.4.Final.jar hibernate-jpa-2.0-api-1.0.0.Final.jar hibernate-validator-4.1.0.Final.jar I am using Annotations to handle the transactional aspect of the application, no problem there. But there are other parts of the application that require very complex queries, and the way I had it

NHibernate Fluent and named Queries

落爺英雄遲暮 提交于 2019-12-04 03:41:49
问题 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> FluentConfiguration cfg = Fluently.Configure().Database(MsSqlConfiguration.MsSql2005.ConnectionString( c => c.Is(dbConnectionString)).ShowSql()) .Mappings(m => m.FluentMappings.AddFromAssembly

@NamedNativeQuery with @SqlResultSetMapping for non-entity

社会主义新天地 提交于 2019-12-04 03:11:51
I have been using this post as an example. I have a complex join query (simplified here). It returns a subset of values from two tables (and a derived column using CASE). I don't think I need to use an entity annotation because the object returned from my result set is not an actual table in my schema. My non-entity object that I want to hold results from my join query: @SqlResultSetMapping( name="myMapping", classes={ @ConstructorResult( targetClass=CarLimitDelta.class, columns={ @ColumnResult(name="caseCol"), @ColumnResult(name="colA"), @ColumnResult(name="colB"), } ) } ) @NamedNativeQuery

JPQL query with WHERE on nested fields

◇◆丶佛笑我妖孽 提交于 2019-12-03 19:59:28
问题 I have a java entity class UserBean with a list of events: @OneToMany private List<EventBean> events; EventBean has Date variable: @Temporal(javax.persistence.TemporalType.TIMESTAMP) private Date eventDate; Now in UserBean I want to create a NamedQuery that returns all dates that fall within a specific range: @NamedQuery(name="User.findEventsWithinDates", query="SELECT u.events FROM UserBean u WHERE u.name = :name AND u.events.eventDate > :startDate AND u.events.eventDate < :endDate") The

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

蓝咒 提交于 2019-12-03 12:50:15
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? Maybe I'm misreading the question, but you don't have to switch to hbm mapping completely. You could continue to use fluent NHibernate to map classes and use hbm for named queries only. In your configuration, you'd then include the entities and the hbms. _sessionFactory = Fluently.Configure() .Mappings(m => { m.FluentMappings