admin管理员组文章数量:1401256
recently I have updated spring boot from 3.3.8 to newer version which is 3.4.1 and suddenly I have started to face a lot of new problems with integration tests. Few of them were really easy to adjust, but I am struggling with one which is really weird (at least in my opinion). Our integration tests are executed in test containers.
Okay, so here is my example:
My test:
@Test
void test1() throws Exception {
Optional<Customer> priceCalculationCustomer = customerRepository.findById(CustomerId.builder().customerId("PRICE_MAIN").salesOrg("PRIC").build());
var book = quotationRepository.findByCustomer(priceCalculationCustomer.get()).getFirst();
BookDto requestBody = BookDto.builder()
.bookId(book.getId())
.build();
mvc.perform(
MockMvcRequestBuilders.post(BASE_PATH + BOOK_PATH)
.contentType(MediaType.APPLICATION_JSON)
.content(convertObjectToJsonBytes(requestBody))
.with(jwtRequestPostProcessor))
.andExpect(status().isOk());
}
My controller:
@PostMapping(value = BOOK_PATH, produces = MediaType.APPLICATION_JSON_VALUE)
public void addQuotationDetails(@RequestBody final BookDto bookDto) {
addBookDetailService.addBookDto(bookDto);
}
My service:
@Transactional
public void addBookDto(BookDto bookDto) {
var book = bookFindService.fetchBook(bookDto.getBookId());
book.getDetails().size();
}
My book find service:
public Book fetchBook(long id) {
return bookRepository.findById(id)
.orElseThrow(() -> new NotFoundProblem(
"book %s does not exist.".formatted(
id)));
}
And I have started to face error in my service, when I try to fetch details of book I receive such an error:
Caused by: java.lang.AssertionError: null
Unable to evaluate the expression Method threw 'java.lang.AssertionError' exception.
It looks like entity manager is losing transaction and it is not able to fetch lazy loaded details, but I have no idea why. This problem does not occur in the application, only in our integration test. This is not a single case, I have multiple cases like this (same story).
My book entity:
@OneToMany(mappedBy = "book", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
private List<Detail> details;
My book details:
@ManyToOne(optional = false, fetch = FetchType.LAZY)
@JoinColumn(name = "id", nullable = false)
private Book book;
本文标签:
版权声明:本文标题:hibernate - Spring 3.4.1 integration test-> Unable to evaluate the children renderer expression Method threw 'jav 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744201499a2594984.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论