AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-21970245

PAMPA ROY's questions

Martin Hope
PAMPA ROY
Asked: 2025-04-10 21:14:32 +0800 CST

我们正在从 Spring 2.xx(Hibernate 5)迁移到 Spring 3.xx(Hibernate 6)。测试用例我们使用了 H2。但是遇到了唯一键约束问题。

  • 5

实体类

@Getter
@Setter
@NoArgsConstructor
@Entity
@ToString
@Table(name = "category_config")
public class CategoryConfig extends BaseEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @NotNull(groups = Existing.class)
    @Null(groups = New.class)
    private Long categoryConfigId;

服务等级

公共 CategoryConfig 添加类别(CategoryConfig

categoryConfig,String tenantId) {
    log.info(" info categoryConfig {} ", categoryConfig);
    if (categoryConfig == null||categoryConfig.getDeptNbr()==null) {
        throw new AllocationRuntimeException(ErrorCodes.CATEGORY_NUMBER_MANDATORY.getError());
    }
    categoryConfig.setTenantId(tenantId);
    categoryConfig.setAllocationStatus(ItemSetupAllocationStatus.PROGRESS.getValue());
    categoryConfig.setItemType(ItemType.INSEASON.getValue());
    try {
        return categoryConfigRepository.save(categoryConfig);
    } catch (Exception e) {
        throw new AllocationRuntimeException(e,
                ErrorCodes.CATEGORY_NUMBER_ALREADY_CONFIGURED.getError(categoryConfig.getDeptNbr()));
    }
}

h2配置:

spring:
    cloud:
        gcp:
          core:
            enabled: false
          bigquery:
            datasetName: test
            project-id: test
            enabled: false
        azure:
           storage:
              blob:
                storage-url: https://test.blob.core.windows.net
    datasource:
        driver-class-name: org.h2.Driver
        url: jdbc:h2:mem:testdb;DB_CLOSE_ON_EXIT=FALSE
        username:
        password:
    jpa:
        defer-datasource-initialization: true
        database-platform: org.hibernate.dialect.H2Dialect
        show-sql: true
        properties:
            hibernate:
                format_sql: true
                ddl-auto: update

h2内部的数据:

INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(1, 202, 'edit cat test', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_us', 'Allocation available', 'inseason,preseason',7)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(2, 12, 'cat test 12', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(3, 14, 'cat test 14', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(4, 7, 'JUGUETES', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(5, 1990, 'edit cat test', 's0r0e4g', '2023-05-30', 's0r0e4g', '2023-05-30', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_us', 'Allocation available', 'inseason',8)
INSERT INTO category_config(category_config_id, dept_nbr, dept_desc, created_by, created_on, last_updated_by, last_updated_on, sum_need_qty_cdf, sum_need_qty_legacy, allocated_items, wk_supply, wk_supply_legacy, allocation_description, inherit_global_decile, isVLTRequired, tenant_id, allocation_status, item_type, current_doh) VALUES(6, 5000, 'test cat', 's0k06wm', '2022-08-26', 's0k06wm', '2022-08-26', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 'sams_mx', 'Allocation available', 'inseason,preseason',8)

它在 Spring 2.xx 中运行良好,但在 Spring 3.xx 中我得到了

could not execute statement [Unique index or primary key violation: "PRIMARY KEY ON PUBLIC.CATEGORY_CONFIG(CATEGORY_CONFIG_ID) ( /* key:1 */ NULL, 7, NULL, 202, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, CAST(1 AS BIGINT), TIMESTAMP '2022-08-26 00:00:00', TIMESTAMP '2022-08-26 00:00:00', NULL, 'Allocation available', 's0k06wm', 'edit cat test', 'inseason,preseason', 's0k06wm', 'sams_us')"; SQL statement:
insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default) [23505-224]] [insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default)]; SQL [insert into category_config (allocated_items,allocation_description,allocation_status,created_by,created_on,current_doh,current_stock_pct,dept_desc,dept_nbr,inherit_global_decile,isvltrequired,item_type,last_updated_by,last_updated_on,margin_onhand,profit,sales_amt,sales_qty,sum_need_qty_cdf,sum_need_qty_legacy,tenant_id,total_oh_qty,wk_supply,wk_supply_legacy,category_config_id) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,default)]; constraint [PRIMARY KEY]

使用 h2 版本 2.2.224

之前运行正常。在 Hibernate 6 中 GenerationType.IDENTITY 是否存在问题?顺便说一下,我们在调用 save 方法时将 categoryConfigId 设置为 null。另外,我没有在 H2 中显式声明创建表,因为之前的版本不需要这样做。

spring-boot
  • 1 个回答
  • 25 Views
Martin Hope
PAMPA ROY
Asked: 2025-02-05 22:09:04 +0800 CST

JPQL 无法识别列

  • 5

实体:

@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();
    }
}

我正在运行这个查询:

@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);

我收到此错误:

原因:java.lang.IllegalArgumentException:org.hibernate.QueryException:无法解析属性:last_updated_on:com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails [从 com.walmart.sams.services.allocation.configuration.service.model.FlowPlanDetails f 中选择 f,其中 f.last_updated_on 位于:startDate 和:endDate 之间且 f.plan_status=:planStatus 且 f.is_archived=:isArchived 且 f.cat_desc=:catDesc]

现在 last_updated_on 列来自 BaseEntity。如何解决?

spring-boot
  • 1 个回答
  • 16 Views
Martin Hope
PAMPA ROY
Asked: 2024-11-11 01:31:32 +0800 CST

Python - SyntaxError:名称“point_to_managedDB”在全局声明之前被分配

  • 5
point_to_managedDB = None

def _get_correct_DB_flag():
    if ENV == "dev":
        global point_to_managedDB
        point_to_managedDB = os.environ.get("OIA_POINT_TO_MANAGED_DB_DEV")
    elif ENV == "stg":
        global point_to_managedDB
        point_to_managedDB = os.environ.get("OIA_POINT_TO_MANAGED_DB_STG")
    elif ENV == "prod":
        global point_to_managedDB
        point_to_managedDB = os.environ.get("OIA_POINT_TO_MANAGED_DB_PROD")

_get_correct_DB_flag()

这段代码有什么问题?我得到:

   File "/oia_application/scripts/database/env/sql_environments.py",
 line 37
     global point_to_managedDB
     ^ 
     SyntaxError: name 'point_to_managedDB' is assigned to before global declaration

我知道 SO 中也问过类似的问题,但我搞不清楚我的代码哪里错了。我只在方法内部声明了全局。

python
  • 1 个回答
  • 19 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve