-1

Below is my Plain POJO object which is having all the mappings. Note that it is not an Entity object.

import javax.persistence.ColumnResult;
import javax.persistence.ConstructorResult;
import javax.persistence.NamedNativeQuery;
import javax.persistence.SqlResultSetMapping;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@AllArgsConstructor
@SqlResultSetMapping(name = "refundReportMapping", classes = { @ConstructorResult(targetClass = RefundReport.class, columns = {
        @ColumnResult(name = "customer_name"),
        @ColumnResult(name = "hashed_email"), @ColumnResult(name = "address"),
        @ColumnResult(name = "partner_order"),
        @ColumnResult(name = "refund_amount") }) })
@NamedNativeQuery(name = "findRefundReportByStatusNamesParamsNative", query = "SELECT concat(bd.first_name,' ',bd.last_name) as 'customer_name',bd.email_address AS 'hashed_email',concat(bd.address1,' ',bd.address2) AS 'address',"
        + o.reservation_id AS 'partner_order',"
        + "(oa.principal_amount+oa.shipping_amount+oa.tax_amount) AS 'refund_amount'"
        + "FROM orders o, order_adjustments oa WHERE oa.status = :status"
        + "and o.buyer_detail_id=bd.buyer_detail_id and o.reservation_id=oa.order_id", resultClass = RefundReport.class, resultSetMapping = "refundReportMapping")
public class RefundReport {

    private String customerName, email, address, 
            partnerOrder;
    private BigDecimal partilaRefundAount;

}
public interface RefundReportRepository extends
        Repository<RefundReport, String> {

    List<RefundReport> findRefundReportByStatus(
            @Param("status") String status);

}
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
sbhargavs
  • 1
  • 2
  • The SqlResultSetMapping and NamedNativeQuery annotations need to be on an Entity, not on the non-entity POJO. https://stackoverflow.com/a/49536120/1116320 – HaseebR7 Nov 13 '18 at 16:15
  • I tried even that as well by providing the Entity, but it is expecting Identifier. My pojo dont have any Id column. – sbhargavs Nov 14 '18 at 05:06
  • I tried even that as well by providing the Entity, but it is expecting Identifier. My pojo don't have any Id column. So my question is can we define an Identifier in Entity without having ID id column in table. – sbhargavs Nov 14 '18 at 05:28

2 Answers2

0

There are multiple problems with this code.

  1. Repository needs two type parameters. The entity type it is a repository for and the type of the id type. Without stating these types Spring Data determines Object for both types which don't work because Object is not a managed entity. Also, if you intend to use RefundReport it needs to be a JPA managed entity.

  2. As pointed out by @HaseebR7 the annotations for named queries and the like must be on an entity as well.

Since it seems you just want to execute a query, you might use any entity, but it has to be a proper entity with an id.

Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
0

Add the below line in your Spring boot application and provide the package name containing entity classes.

@EntityScan(basePackages = {"com.example.entity"})
Krishna Majgaonkar
  • 1,532
  • 14
  • 25