最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

spring boot - JPQL cant recognize column - Stack Overflow

programmeradmin0浏览0评论

Entity:

@Getter
@Setter
@NoArgsConstructor
@Entity
@ToString
@DynamicUpdate
@Table(name = "flow_plan_details")
public class FlowPlanDetails extends BaseEntity{
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Existing.class)
    @Null(groups = New.class)
    private Long flowPlanId;
    
    private Integer itemNbr;
    private String itemDescription;
    private String season;
    private Integer fiscalYear;
    private String catDesc;
    private String subcatDesc;
    private String gmm;
    private String dmm;
    private String planStatus;
    private String channel;
    
    private Boolean isLcl;
    private String imageUrl;
    private Integer carryOverItemNbr;
    private Integer palletQty;
    private Integer totalContQty;
    private Integer commitmentQty;
    private Integer defaultPresentation;
    private LocalDate inClubDate;
    private LocalDate oosDate;
    private String eventCode;
    private Integer clubCount;
    private Integer percContainerRoundUp;
    private String portOfOrigin;
    private String productId;
    
    
    private String flowRounding;
    private String breakdownCalculation;
    private Integer wos;
    private Integer lastWeekToReceive;
    private String targetOhRule;
    
    
    private Float itemCost;
    private Float itemRetail;
    private Float shippingCostPerPallet;
    private Float shippingCostPerContainer;
    private Float profitPerItem;
    private Float lostSale;
    private Float containerShippingCost;
    private Float totalCost;
    
    
    private String holidayName;
    private LocalDate holidayStartDate;
    private LocalDate holidayEndDate;
    private LocalDate holidayDate;
    private String applyHoliday;
    
    
    private Float plannedContainers;
    private Float plannedPallets;
    private Float flowContainers;
    private Float flowPallets;
    private Float differenceInContainers;
    private Float differenceInPallets;

    private LocalDateTime lastGeneratedFlowPlan;
    private Long rolloutId;
    private Boolean isRolloutRefreshRequired;
    private Boolean isArchived = false;

    private Float weight;
    private Float dimension1;
    private Float dimension2;
    private Float dimension3;
    private Boolean sorted;

    private String impactDropdown;
    private Boolean isReadyForScgs;
    private String finalizedStatus;
    
    public interface Existing {
    }

    public interface New {
    }

    public String getFlowplanIdWithName()
    {
        return this.getFlowPlanId().toString()+" - "+this.getItemDescription()+" - "+ this.getChannel();
    }
}

Im running this query:

@Query("""
       select f from FlowPlanDetails f
       where f.last_updated_on between :startDate and :endDate
       and f.plan_status=:planStatus and f.is_archived=:isArchived
       and f.cat_desc= :catDesc
       """) //(:catDesc is NULL OR f.cat_desc= :catDesc)
Page<FlowPlanDetails> customSpotQuery(@Param("catDesc") String catDesc,
        @Param("startDate") ZonedDateTime startDate,
        @Param("endDate") ZonedDateTime endDate,
        @Param("planStatus") String planStatus,
        @Param("isArchived") Boolean isArchived, Pageable page);

Im getting this error:

Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: last_updated_on of: com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails [select f from com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails f where f.last_updated_on between :startDate and :endDate and f.plan_status=:planStatus and f.is_archived=:isArchived and f.cat_desc= :catDesc]

Now last_updated_on column comes from BaseEntity. How to solve it?

Entity:

@Getter
@Setter
@NoArgsConstructor
@Entity
@ToString
@DynamicUpdate
@Table(name = "flow_plan_details")
public class FlowPlanDetails extends BaseEntity{
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Existing.class)
    @Null(groups = New.class)
    private Long flowPlanId;
    
    private Integer itemNbr;
    private String itemDescription;
    private String season;
    private Integer fiscalYear;
    private String catDesc;
    private String subcatDesc;
    private String gmm;
    private String dmm;
    private String planStatus;
    private String channel;
    
    private Boolean isLcl;
    private String imageUrl;
    private Integer carryOverItemNbr;
    private Integer palletQty;
    private Integer totalContQty;
    private Integer commitmentQty;
    private Integer defaultPresentation;
    private LocalDate inClubDate;
    private LocalDate oosDate;
    private String eventCode;
    private Integer clubCount;
    private Integer percContainerRoundUp;
    private String portOfOrigin;
    private String productId;
    
    
    private String flowRounding;
    private String breakdownCalculation;
    private Integer wos;
    private Integer lastWeekToReceive;
    private String targetOhRule;
    
    
    private Float itemCost;
    private Float itemRetail;
    private Float shippingCostPerPallet;
    private Float shippingCostPerContainer;
    private Float profitPerItem;
    private Float lostSale;
    private Float containerShippingCost;
    private Float totalCost;
    
    
    private String holidayName;
    private LocalDate holidayStartDate;
    private LocalDate holidayEndDate;
    private LocalDate holidayDate;
    private String applyHoliday;
    
    
    private Float plannedContainers;
    private Float plannedPallets;
    private Float flowContainers;
    private Float flowPallets;
    private Float differenceInContainers;
    private Float differenceInPallets;

    private LocalDateTime lastGeneratedFlowPlan;
    private Long rolloutId;
    private Boolean isRolloutRefreshRequired;
    private Boolean isArchived = false;

    private Float weight;
    private Float dimension1;
    private Float dimension2;
    private Float dimension3;
    private Boolean sorted;

    private String impactDropdown;
    private Boolean isReadyForScgs;
    private String finalizedStatus;
    
    public interface Existing {
    }

    public interface New {
    }

    public String getFlowplanIdWithName()
    {
        return this.getFlowPlanId().toString()+" - "+this.getItemDescription()+" - "+ this.getChannel();
    }
}

Im running this query:

@Query("""
       select f from FlowPlanDetails f
       where f.last_updated_on between :startDate and :endDate
       and f.plan_status=:planStatus and f.is_archived=:isArchived
       and f.cat_desc= :catDesc
       """) //(:catDesc is NULL OR f.cat_desc= :catDesc)
Page<FlowPlanDetails> customSpotQuery(@Param("catDesc") String catDesc,
        @Param("startDate") ZonedDateTime startDate,
        @Param("endDate") ZonedDateTime endDate,
        @Param("planStatus") String planStatus,
        @Param("isArchived") Boolean isArchived, Pageable page);

Im getting this error:

Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: last_updated_on of: com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails [select f from com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails f where f.last_updated_on between :startDate and :endDate and f.plan_status=:planStatus and f.is_archived=:isArchived and f.cat_desc= :catDesc]

Now last_updated_on column comes from BaseEntity. How to solve it?

Share Improve this question edited Feb 5 at 14:28 Joop Eggen 110k8 gold badges87 silver badges140 bronze badges asked Feb 5 at 14:09 PAMPA ROYPAMPA ROY 512 silver badges9 bronze badges 2
  • What does your BaseEntity look like? And does your flow_plan_details table have the last_updated_on column when you check it in the db directly? – CodingCoder Commented Feb 5 at 14:18
  • 1 One would expect a BaseEntity with lastUpdatedOn by the code. – Joop Eggen Commented Feb 5 at 14:34
Add a comment  | 

1 Answer 1

Reset to default 1

JPQL works with entity property names (the fields or getter/setter methods in your Java class) rather than the actual database column names. So if your last_updated_on is a field in your BaseEntity class, and your entity uses camelCase for property names, you should use f.lastUpdatedOn in your query instead of f.last_updated_on.

发布评论

评论列表(0)

  1. 暂无评论