【发布时间】:2015-08-06 14:59:19
【问题描述】:
我有一个名为 InventoryLineItem 的域类,它有一个 InventoryAccess 类型的属性:
class InventoryLineItem {
InventoryAccess inventoryAccess
...
}
还有一个名为 LineItem 的域类具有 InventoryLineItem 类型的属性:
class LineItem {
InventoryLineItem inventoryLineItem
...
}
我面临的问题是,当我尝试从 LineItem 类(例如inventoryLineItem.inventoryAccess?.allotment)访问 InventoryAccess 的任何属性时,出现以下异常:
java.lang.IllegalStateException: Proxy for [com.acme.inventory.domain.InventoryAccess:8604205056156879654] could not be initialized
我将实例获取到 LineItem 实例,如下所示:
List<LineItem> lineItemsPendingTransfer = originalDeliveredItemIds.collect { Long id ->
InventoryLineItem.get(id)?.lineItem
}
然后,我遍历每个订单项,并为每个订单项调用 LineItem 中的一个方法来执行此操作:
if (inventoryLineItem.inventoryAccess?.allotment?.scannableEndDate?.before(new Date())) {
return LineItemTransferState.buildUnavailableState(UnavailableTransferReason.OUTDATED)
}
这就是问题发生的地方。一旦我尝试从inventoryAccess 对象中获取allotment 属性,就会引发异常。
我尝试将 InventoryLineItem 中的 inventoryAccess 属性设置为 lazy: false,但这没有帮助。
【问题讨论】:
-
您需要为您的问题提供更多背景信息。您试图在您的应用程序中的哪个位置访问它?你是如何获得inventoryLineItem 的实例的?这是在控制器中吗?服务?标签库?包含应用程序该部分的代码。
-
我在原始消息中添加了一些上下文。感谢您的帮助。
-
InventoryAccess 是域类吗?
标签: hibernate grails grails-orm grails-2.0