ModelService不会删除groovy脚本中的模型

omqzjyyz  于 2022-11-01  发布在  其他
关注(0)|答案(2)|浏览(137)

我试图在groovy脚本中使用ModelService从数据库中删除一个模型,但它没有删除。

import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.ordersplitting.model.ConsignmentModel

List<String> orderList = new ArrayList<>()
orderList.add("P000015003")

OrderModel orderModel = flexibleSearchService.search(String.format("SELECT {PK} FROM {AbstractOrder} WHERE {code} = '%s'", "P000015003")).result.get(0)
ConsignmentModel consignment = orderModel.getConsignments().iterator().next()
ModelService modelService = (ModelService) spring.getBean("modelService");
modelService.remove(consignment)
println("Removed")
qnakjoqk

qnakjoqk1#

您是否已检查“commit”模式是否已打开,如下图所示?

44u64gxh

44u64gxh2#

您可以使用transaction执行提交操作:

import de.hybris.platform.core.model.order.OrderModel
import de.hybris.platform.ordersplitting.model.ConsignmentModel

def tx = de.hybris.platform.tx.Transaction.current()

tx.begin()

List<String> orderList = new ArrayList<>()
orderList.add("P000015003")

OrderModel orderModel = flexibleSearchService.search(String.format("SELECT {PK} FROM {AbstractOrder} WHERE {code} = '%s'", "P000015003")).result.get(0)
ConsignmentModel consignment = orderModel.getConsignments().iterator().next()
ModelService modelService = (ModelService) spring.getBean("modelService");
modelService.remove(consignment)
println("Removed") 

tx.commit()

相关问题