Questions tagged [sqlresultsetmapping]

81 questions
63
votes
9 answers

Efficient way to Handle ResultSet in Java

I'm using a ResultSet in Java, and am not sure how to properly close it. I'm considering using the ResultSet to construct a HashMap and then closing the ResultSet after that. Is this HashMap technique efficient, or are there more efficient ways of…
Deepak
  • 6,684
  • 18
  • 69
  • 121
50
votes
11 answers

How to map the result set of a JPA NativeQuery to a POJO using SqlResultSetMapping

I am attempting to map the results of a Native query to a POJO using @SqlResultSetMapping with @ConstructorResult. Here is my code: @SqlResultSetMapping(name="foo", classes = { @ConstructorResult( targetClass =…
mhlandry
  • 675
  • 1
  • 6
  • 14
19
votes
4 answers

JPA Data Repositories with SqlResultSetMapping and native queries

I was stuck with the following situation: My entities are related to each other, but in such a way that i could not use JPQL. I was forced to use native SQL. Now I want to map these results to a ValueObject. To be clear, I don't want to get a list…
LeoRado
  • 331
  • 1
  • 3
  • 10
11
votes
1 answer

@NamedNativeQuery with @SqlResultSetMapping for non-entity

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…
Micho Rizo
  • 1,000
  • 3
  • 12
  • 27
11
votes
3 answers

@ConstructorResult with Enum in JPA 2.1

I am not having any idea how to use Enum in @ColumnResult Type while using @ConstructorResult of @SqlResultSetMapping @SqlResultSetMapping(name="DetailAndResult", classes={ …
Vik
  • 125
  • 1
  • 9
9
votes
1 answer

How to map ONE-TO-MANY native query result into a POJO class using @SqlResultSetMapping

Im working in a backend API using Java and MySql, and I'm trying to use @SqlResultSetMapping in JPA 2.1 for mapping a ONE-TO-MANY native query result into a POJO class, this is the native query: @NamedNativeQuery(name = "User.getAll”, query =…
Tamer Saleh
  • 473
  • 9
  • 21
8
votes
1 answer

SqlResultSetMapping columns as and entities

I am really confused, how does column resultset mapping work? What am I mapping when I use columns instead of entities? Look at this example... Query q = em.createNativeQuery( "SELECT o.id AS order_id, " + "o.quantity AS…
SoftwareSavant
  • 9,467
  • 27
  • 121
  • 195
6
votes
1 answer

JPA mapping native query result to non entity DTO

I have a complex native query and I am trying to map its result to a non-entity DTO class. I am trying to use JPA's SqlResultSetMapping with ConstructorResult My DTO class @Data public class Dto { private Long id; private String serial; …
Tartar
  • 5,149
  • 16
  • 63
  • 104
5
votes
1 answer

Result set mapping in Grails / GORM

I want to map the result of a native SQL query to a simple bean in grails, similar to what the @SqlResultSetMapping annotation does. For example, given a query select x.foo, y.bar, z.baz from //etc... map the result to class FooBarBaz { String…
armandino
  • 17,625
  • 17
  • 69
  • 81
4
votes
1 answer

JPA native join fetch

It's well known that we can retrieve an entity and all its children in a single JPQL query using join fetch. However, I can't seem to get this working with a native query. I'm getting [Ljava.lang.Object; cannot be cast to…
Steve
  • 8,066
  • 11
  • 70
  • 112
4
votes
1 answer

JPA native query result returns duplicate child objects

I have a parent table and a child Table in my DB, and have a OneToMany mapping for them in their corresponding entity classes. The child table has a foreign key parent_id. I am using JPA 2 with Hibernate and MySQL DB. I wish to retrieve all the…
4
votes
1 answer

symfony2 doctrine ResultSetMapping error

Here I am try to use ResultSetMapping to map the result which generate by nativeQuery. But I have no idea about why the doctrine always throw Undefined index error. anyone can help me out from this problem? Here is my code: the…
leoyfm
  • 241
  • 4
  • 16
3
votes
2 answers

Trying to put the Result set Values inside a Map

I'm trying to put the Result Set (DB Query Values) inside a LinkedHashMap>. Every Iteration of row. The value is getting overriden while putting into DBMap. > rowData = new LinkedHashMap<>();
3
votes
2 answers

JPA Native Query Result Set Mapping with repeating data and a list

I'd like to map data from a native query to an object with a list in it. Let's say I have this query (it's a contrived example of what I want to do) select p.id, p.name, a.address, a.city, s.salestotal, s.salesmonth from person p, address a, sales…
JohnL
  • 65
  • 7
3
votes
1 answer

jpa native query retrieve multiple entities

I have a database with 4 tables: company,staff,department,project Company.java @Entity @Table(name = "company") @SqlResultSetMapping(name = "COMPANY", entities = { @EntityResult(entityClass = Company.class), @EntityResult(entityClass =…
KKL Michael
  • 795
  • 1
  • 13
  • 31
1
2 3 4 5 6