diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLine.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLine.kt index 6db837d..b3084af 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLine.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLine.kt @@ -16,18 +16,18 @@ import jakarta.validation.constraints.NotNull import org.hibernate.annotations.JdbcTypeCode import org.hibernate.type.SqlTypes import java.math.BigDecimal - +import jakarta.persistence.FetchType @Entity @Table(name = "inventory_lot_line") open class InventoryLotLine : BaseEntity() { // @JsonBackReference @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "inventoryLotId") open var inventoryLot: InventoryLot? = null @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "warehouseId") open var warehouse: Warehouse? = null @@ -38,7 +38,7 @@ open class InventoryLotLine : BaseEntity() { open var outQty: BigDecimal? = null @NotNull - @ManyToOne + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "stockItemUomId") open var stockUom: ItemUom? = null diff --git a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt index dfd9434..74e628e 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/entity/InventoryLotLineRepository.kt @@ -13,6 +13,7 @@ import java.io.Serializable import com.ffii.fpsms.modules.stock.entity.enum.InventoryLotLineStatus import org.springframework.data.repository.query.Param import java.time.LocalDate +import org.springframework.data.jpa.repository.EntityGraph @Repository interface InventoryLotLineRepository : AbstractRepository { @@ -69,11 +70,31 @@ interface InventoryLotLineRepository : AbstractRepository): List - - @Query("SELECT ill FROM InventoryLotLine ill WHERE ill.warehouse.id IN :warehouseIds AND ill.deleted = false AND ill.status = 'available'") + + // You can also add another one for the status filter if needed + @EntityGraph( + type = EntityGraph.EntityGraphType.FETCH, + attributePaths = ["inventoryLot", "inventoryLot.item", "warehouse", "stockUom", "stockUom.uom"] + ) + @Query(""" + SELECT ill + FROM InventoryLotLine ill + WHERE ill.warehouse.id IN :warehouseIds + AND ill.deleted = false + AND ill.status = 'available' + """) fun findAllByWarehouseIdInAndDeletedIsFalseAndStatusIsAvailable(@Param("warehouseIds") warehouseIds: List): List @Query(""" @@ -95,6 +116,7 @@ interface InventoryLotLineRepository : AbstractRepository + @Query(""" SELECT COUNT(DISTINCT ill.inventoryLot.item.id) FROM InventoryLotLine ill