Modelservice不会在Groovy脚本中删除模型

发布于 2025-01-27 07:04:58 字数 640 浏览 4 评论 0原文

我正在尝试使用我的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") 

I'm trying to remove a model from database using ModelService in my groovy script but it doesn't remove.

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") 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

逆蝶 2025-02-03 07:04:58

您是否检查过“提交”模式是否如下图所示?

Have you checked if the 'commit' mode is ON as shown in the image below?
enter image description here

原野 2025-02-03 07:04:58

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

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()

You could use transaction to perform commit operation:

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文