我有两个实体,ManyToOne Relationship和Lazy Fetch类型:
@Entity
public class Item {
private Long id;
private String title;
@ManyToOne(fetch = FetchType.LAZY)
private Category category;
}
@Entity
public class Category {
private Long id;
private String title;
}
我有DTO:
public class ItemDTO {
private Long id;
private String title;
private Long categoryId;
}
当我从数据库获取项目时,我使用mapstruct将它们映射到ItemDTO,其中我有以下规则:
@Mapping(source = "category.id", target = "categoryId")
ItemDTO itemToItemDTO(Item item);
而且一切都运行得很完美,但问题是mapstruct在其impl类中如何以及在哪里获得有关惰性获取的类别的数据?
我有过
show-sql: true
在属性中,在映射发生时看不到任何其他查询.有人能给我解释一下它是怎么工作的吗?