在我们的应用程序中,每天有几个不同的用户(根据 Plumbr 的说法约为 20 个)遇到以下异常
Error: Loading initial props cancelled
我们已经确定错误来自_getData<T>
router.ts 中的方法,但无法找出原因或重现它。我们尝试使用 Chrome 开发工具添加限制,并执行快速连续调用路由器但没有骰子的多个操作。
导致错误的原因是什么?
我正在尝试使用 Spring Data JPA (2.1) 和 Hibernate 在 PostgreSQL 上执行 SKIP LOCKED 查询。查询如下所示:
@Lock(LockModeType.PESSIMISTIC_WRITE)
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value ="-2")})
List<Obj> findByEntityAndStatus(Entity entity, Status status);
Run Code Online (Sandbox Code Playgroud)
根据Spring data JPA native queryskiplocked和Select for updateskiplocked from JPA level它应该可以工作,但生成的查询仅选择更新而不跳过锁定的行。
生成的查询:
休眠:从objs obj0_左外连接实体entity1_上选择obj0_.id作为id1_5_,obj0_.name作为name6_5_,obj0_.entity_id作为entity10_5_,obj0_.status作为status8_5_,在obj0_.entity_id=entity1_.id上,其中entity1_.id=?和 obj0_.status=?用于更新 obj0_
我缺少什么?
我在测试 Spring DataJpaTest 中是否加载了集合时遇到了麻烦。
为此,我创建了一个具有 id 和项目列表的实体,如下所示。该列表应该是延迟加载的(所以我假设它不应该在测试中加载)。
@Data
@Entity
@Table(name = "examples")
public class Example {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
@OneToMany(mappedBy = "example", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
private List<ExampleElement> collection;
}
Run Code Online (Sandbox Code Playgroud)
存储库代码如下所示:
@Repository
public interface ExampleRepository extends PagingAndSortingRepository<Example, Long> {
@Query("SELECT e FROM Example e")
List<Example> findAllActive();
}
Run Code Online (Sandbox Code Playgroud)
在测试中,我正在创建一个新的 Example 实体,生成集合,将实体保存到数据库,然后从数据库中获取实体并检查集合是否已初始化。测试代码如下所示:
@RunWith(SpringRunner.class)
@DataJpaTest
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class ExampleRepositoryTest {
@Autowired
private ExampleRepository repository;
@Test
public void myTest() {
Example example = new Example();
example.setCollection(Utils.generateCollection())) …
Run Code Online (Sandbox Code Playgroud)