小编Ken*_*ark的帖子

使用 H2 的 DataJpaTest 无法访问 Subselect 实体中的数据

我正在使用 H2 数据库运行设置为 DataJpaTest 的单元测试。它运行良好,直到我使用子选择引入了一个新的不可变实体集。它不会中断,但它找不到应有的数据。我在 SQL 中看到它正确地连接到 Subselect 查询。

当像应用程序一样正常运行时,@Subselect 实体工作正常,因此这在某种程度上是单元测试设置的问题。

这是我的主要实体:

@Entity
@DynamicUpdate
@Getter
@Setter
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = false)
@Table(name = "apps", schema = "public")
public class App extends BaseEntity
{
    @Id
    @Column(name = "app_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ent_generator")
    @SequenceGenerator(name = "ent_generator", sequenceName = "entity_seq", allocationSize = 1)
    private long appId;

    @EqualsAndHashCode.Include
    @Basic
    @Column(name = "app_name", length = 200)
    private String appCode;

    @EqualsAndHashCode.Include
    @Basic
    @Column(name = "app_ver_name", length = 200)
    private String …
Run Code Online (Sandbox Code Playgroud)

unit-testing jpa h2 spring-data-jpa spring-boot

8
推荐指数
1
解决办法
328
查看次数

标签 统计

h2 ×1

jpa ×1

spring-boot ×1

spring-data-jpa ×1

unit-testing ×1