gpt4 book ai didi

JavaEE : Does EntityManager get method changing state in DB

转载 作者:行者123 更新时间:2023-12-02 10:50:27 26 4
gpt4 key购买 nike

我想知道是否可以对该本地列表中的每个元素执行 em.remove ?此代码是否会更改数据库中的状态?

TypedQuery<Product> query = em.createNamedQuery("Product.findByCode", Product.class);
query.setParameter("code", code);
List<Product> productList= query.getResultList();
for (int i = 1; i < productList.size(); i++) {
em.remove(productList.get(i));
}

最佳答案

是的,它改变了数据库,因为那是他的工作。

The EntityManager API is used to create and remove persistent entity instances, to find entities by their primary key, and to query over entities.

https://docs.oracle.com/javaee/7/api/javax/persistence/EntityManager.html

关于JavaEE : Does EntityManager get method changing state in DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52225517/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com