当前位置: 首页 > 知识库问答 >
问题:

删除(可迭代 itrbl) 在 Crud 存储库中扩展和在 Jpa 存储库中扩展在批处理(可迭代 itrbl)之间有什么区别

云默
2023-03-14

我在尝试删除具有外键的实体列表时遇到问题。< code>CrudRepository中delete方法可以很好地处理没有外键的表,但是当我尝试删除具有外键的实体列表时,它报告成功,但是没有在数据库中删除任何内容。< code>deleteInBatch()在这两种情况下都能正常工作。

方法<code>delete(Iterable)之间的区别是什么

我经历过这个。

任何帮助都将不胜感激

我的模型SmsNotifyTemplate.java:

package com.viettel.pcrf.webconfig.model;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Anh Nguyen
 */
@Entity
@Table(name = "SMS_NOTIFY_TEMPLATE", catalog = "", schema = "VPCRF")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "SmsNotifyTemplate.findAll", query = "SELECT s FROM SmsNotifyTemplate s"),
    @NamedQuery(name = "SmsNotifyTemplate.findBySmsNotifyTemplateId", query = "SELECT s FROM SmsNotifyTemplate s WHERE s.smsNotifyTemplateId = :smsNotifyTemplateId"),
    @NamedQuery(name = "SmsNotifyTemplate.findByMessageTemplate", query = "SELECT s FROM SmsNotifyTemplate s WHERE s.messageTemplate = :messageTemplate"),
    @NamedQuery(name = "SmsNotifyTemplate.findByComments", query = "SELECT s FROM SmsNotifyTemplate s WHERE s.comments = :comments"),
    @NamedQuery(name = "SmsNotifyTemplate.findBySmsTemplateCode", query = "SELECT s FROM SmsNotifyTemplate s WHERE s.smsTemplateCode = :smsTemplateCode")})
public class SmsNotifyTemplate implements Serializable {

    public static enum COLUMNS {

        COMMENTS, LANGID, MESSAGETEMPLATE, SMSNOTIFYTEMPLATEID, SMSTEMPLATECODE
    };
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "SMS_NOTIFY_TEMPLATE_ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "sms_notify_template_seq_gen")
    @SequenceGenerator(name = "sms_notify_template_seq_gen", sequenceName = "SMS_NOTIFY_TEMPLATE_SEQ")
    private Short smsNotifyTemplateId;
    @Column(name = "MESSAGE_TEMPLATE", length = 480)
    private String messageTemplate;
    @Column(name = "COMMENTS", length = 200)
    private String comments;
    @Column(name = "SMS_TEMPLATE_CODE")
    private Integer smsTemplateCode;
    @JoinColumn(name = "LANG_ID", referencedColumnName = "LANG_ID", nullable = false)
    @ManyToOne(optional = false)
    private Lang langId;

    public SmsNotifyTemplate() {

    }

    public SmsNotifyTemplate(Short smsNotifyTemplateId) {
        this.smsNotifyTemplateId = smsNotifyTemplateId;
    }

    public Short getSmsNotifyTemplateId() {
        return smsNotifyTemplateId;
    }

    public void setSmsNotifyTemplateId(Short smsNotifyTemplateId) {
        this.smsNotifyTemplateId = smsNotifyTemplateId;
    }

    public String getMessageTemplate() {
        return messageTemplate;
    }

    public void setMessageTemplate(String messageTemplate) {
        this.messageTemplate = messageTemplate;
    }

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public Integer getSmsTemplateCode() {
        return smsTemplateCode;
    }

    public void setSmsTemplateCode(Integer smsTemplateCode) {
        this.smsTemplateCode = smsTemplateCode;
    }

    public Lang getLangId() {
        return langId;
    }

    public void setLangId(Lang langId) {
        this.langId = langId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (smsNotifyTemplateId != null ? smsNotifyTemplateId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SmsNotifyTemplate)) {
            return false;
        }
        SmsNotifyTemplate other = (SmsNotifyTemplate) object;
        return !((this.smsNotifyTemplateId == null && other.smsNotifyTemplateId != null) || (this.smsNotifyTemplateId != null && !this.smsNotifyTemplateId.equals(other.smsNotifyTemplateId)));
    }

    @Override
    public String toString() {
        return "com.viettel.pcrf.model.SmsNotifyTemplate[ smsNotifyTemplateId=" + smsNotifyTemplateId + " ]";
    }

}

我有一个映射器来映射具有法线类的模型:

短信模板映射器.java:

package com.viettel.pcrf.webconfig.mapper;

import com.viettel.fw.common.util.mapper.BaseMapper;
import com.viettel.pcrf.webconfig.dto.SmsTemplateDTO;
import com.viettel.pcrf.webconfig.model.SmsNotifyTemplate;

public class SmsTemplateMapper extends BaseMapper<SmsNotifyTemplate, SmsTemplateDTO> {

    @Override
    public SmsTemplateDTO toDtoBean(SmsNotifyTemplate model) {
        SmsTemplateDTO obj = null;
        if (model != null) {
            obj = new SmsTemplateDTO();
            obj.setComments(model.getComments());
            obj.setMessageTemplate(model.getMessageTemplate());
            obj.setSmsNotifyTemplateId(model.getSmsNotifyTemplateId());
            obj.setSmsTemplateCode(model.getSmsTemplateCode());
            obj.setLangId(model.getLangId());
        }
        return obj;
    }

    @Override
    public SmsNotifyTemplate toPersistenceBean(SmsTemplateDTO dtoBean) {
        SmsNotifyTemplate obj = null;
        if (dtoBean != null) {
            obj = new SmsNotifyTemplate();
            obj.setComments(dtoBean.getComments());
            obj.setMessageTemplate(dtoBean.getMessageTemplate());
            obj.setSmsNotifyTemplateId(dtoBean.getSmsNotifyTemplateId());
            obj.setSmsTemplateCode(dtoBean.getSmsTemplateCode());
            obj.setLangId(dtoBean.getLangId());
            System.out.println(obj.getLangId().getNationality());
        }
        return obj;
    }
}

SmsTemplateDTO.java:

package com.viettel.pcrf.webconfig.dto;

import com.viettel.fw.dto.BaseDTO;
import com.viettel.pcrf.webconfig.model.Lang;
import java.io.Serializable;

public class SmsTemplateDTO extends BaseDTO implements Serializable {

    public String getKeySet() {
        return keySet;
    }
    private String comments;
    private String messageTemplate;
    private Short smsNotifyTemplateId;
    private Integer smsTemplateCode;
    private Lang langId;

    public String getComments() {
        return this.comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    public String getMessageTemplate() {
        return this.messageTemplate;
    }

    public void setMessageTemplate(String messageTemplate) {
        this.messageTemplate = messageTemplate;
    }

    public Short getSmsNotifyTemplateId() {
        return this.smsNotifyTemplateId;
    }

    public void setSmsNotifyTemplateId(Short smsNotifyTemplateId) {
        this.smsNotifyTemplateId = smsNotifyTemplateId;
    }

    public Integer getSmsTemplateCode() {
        return this.smsTemplateCode;
    }

    public void setSmsTemplateCode(Integer smsTemplateCode) {
        this.smsTemplateCode = smsTemplateCode;
    }

    public Lang getLangId() {
        return langId;
    }

    public void setLangId(Lang langId) {
        this.langId = langId;
    }

}

SmsTemplateRepo.java:

package com.viettel.pcrf.webconfig.repo;
import com.viettel.fw.persistence.BaseRepository;
import java.util.List;
import com.viettel.pcrf.webconfig.model.SmsNotifyTemplate;

public interface SmsTemplateRepo extends BaseRepository<SmsNotifyTemplate>, SmsTemplateRepoCustom {


    public List<SmsNotifyTemplate> findByComments(String comments);

    public List<SmsNotifyTemplate> findByMessageTemplate(String messageTemplate);

    public List<SmsNotifyTemplate> findBySmsNotifyTemplateId(Short smsNotifyTemplateId);

    public List<SmsNotifyTemplate> findBySmsTemplateCode(Integer smsTemplateCode);
}

基本存储库扩展了 Jpa存储库。

删除方法将在该类的deleteSmsNotifyTemplates方法中:

SmsTemplateService.java:

package com.viettel.pcrf.webconfig.service;

import com.viettel.fw.common.util.extjs.FilterRequest;
import com.viettel.fw.dto.BaseMessage;
import com.viettel.pcrf.webconfig.repo.SmsTemplateRepo;
import com.viettel.pcrf.webconfig.mapper.SmsTemplateMapper;
import com.viettel.pcrf.webconfig.dto.SmsTemplateDTO;
import com.viettel.pcrf.webconfig.model.SmsNotifyTemplate;
import java.util.List;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 *
 * @author Anh Nguyen
 */
@Service
public class SmsTemplateServiceImpl extends BaseServiceImpl implements SmsTemplateService {

    private final SmsTemplateMapper mapper = new SmsTemplateMapper();

    @Autowired
    private SmsTemplateRepo repository;
    public Logger logger = Logger.getLogger(SmsTemplateService.class);

    @Override
    public BaseMessage deleteSmsNotifyTemplates(List<SmsTemplateDTO> smsNotifyTemplateDTOs) throws Exception {
        BaseMessage baseMessage = new BaseMessage();
        repository.delete(mapper.toPersistenceBean(smsNotifyTemplateDTOs));
        baseMessage.setSuccess(true);
        baseMessage.setOutputObject(smsNotifyTemplateDTOs);
        return baseMessage;
    }         
}

控制器:

SmsTemplateCtrl.java:

package com.viettel.pcrf.webconfig.controller;

import com.viettel.fw.Exception.LogicException;
import com.viettel.fw.common.util.extjs.FilterRequest;
import com.viettel.fw.web.controller.BaseController;
import com.viettel.pcrf.webconfig.dto.LangDTO;
import com.viettel.pcrf.webconfig.dto.SmsTemplateDTO;
import com.viettel.pcrf.webconfig.model.Lang;
import com.viettel.pcrf.webconfig.service.LangService;
import com.viettel.pcrf.webconfig.service.SmsTemplateService;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 *
 * @author Anh Nguyen
 */
@Component("smsNotifyTemplateController")
@Scope("view")
public class SmsTemplateCtrl extends BaseController implements Serializable {

    private List<SmsTemplateDTO> listSmsNotifyTemplate;
    private SmsTemplateDTO smsNotifyTemplate;
    private List<SmsTemplateDTO> selectedSmsNotifyTemplates;
    private List<LangDTO> listLang;

    @Autowired
    private SmsTemplateService smsNotifyTemplateService;

    @Autowired
    private LangService langService;

    public List<SmsTemplateDTO> getListSmsNotifyTemplate() {
        return listSmsNotifyTemplate;
    }

    public void setListSmsNotifyTemplate(List<SmsTemplateDTO> listSmsNotifyTemplate) {
        this.listSmsNotifyTemplate = listSmsNotifyTemplate;
    }

    public SmsTemplateDTO getSmsNotifyTemplate() {
        return smsNotifyTemplate;
    }

    public void setSmsNotifyTemplate(SmsTemplateDTO smsNotifyTemplate) {
        this.smsNotifyTemplate = smsNotifyTemplate;
    }

    public List<SmsTemplateDTO> getSelectedSmsNotifyTemplates() {
        return selectedSmsNotifyTemplates;
    }

    public void setSelectedSmsNotifyTemplates(List<SmsTemplateDTO> selectedSmsNotifyTemplates) {
        this.selectedSmsNotifyTemplates = selectedSmsNotifyTemplates;
    }

    public List<LangDTO> getListLang() {
        return listLang;
    }

    public void setListLang(List<LangDTO> listLang) {
        this.listLang = listLang;
    }

    /**
     * Khoi Tao Cac doi tuong de load len view
     */
    @PostConstruct
    public void init() {
        listSmsNotifyTemplate = smsNotifyTemplateService.findAllSort();
        listLang = langService.findAllSort();
        formStatus = getFormStatus();
    }

    /**
     * Chuan bi cho thao tac delete
     */
    public void delete() {
        try {
            if (selectedSmsNotifyTemplates == null || selectedSmsNotifyTemplates.isEmpty()) {
                reportError("msgInfo", "Choose one row!");
            } else {
                smsNotifyTemplateService.deleteSmsNotifyTemplates(selectedSmsNotifyTemplates);
                reportSuccess("msgInfo", "common.msg.success.delete");
                reset();
                updateController();
            }
        } catch (LogicException logicE) {
            reportError("msgInfo", logicE);
        } catch (Exception exception) {
            reportError("msgInfo", exception.getMessage());
        }
    }

    /**
     * Kiem tra SmsNotifyTemplateId ton tai trong bang SMS_NOTIFY_TEMPLATE
     *
     * @param smsNotifyTemplates
     * @return
     */
    public boolean SmsNotifyTemplateIdExistedInSmsNotifyTemplate(List<SmsTemplateDTO> smsNotifyTemplates) {
        List<FilterRequest> listReq = new ArrayList<>();
        for (SmsTemplateDTO s : smsNotifyTemplates) {
            listReq.add(new FilterRequest("LANGID", s.getLangId()));
        }
        List<SmsTemplateDTO> list = smsNotifyTemplateService.findAll(listReq);
        return !list.isEmpty();
    }

    /**
     * Kiem tra SmsNotifyTemplateCode ton tai trong bang LANG
     *
     * @param smsTemplateCode
     * @param smsNotifyTemplateId
     * @return
     */
    public boolean SmsTemplateCodeExisted(Integer smsTemplateCode, Short smsNotifyTemplateId) {
        List<FilterRequest> listReq = new ArrayList<>();
        listReq.add(new FilterRequest("SMSTEMPLATECODE", smsTemplateCode));
        List<SmsTemplateDTO> list = smsNotifyTemplateService.findAll(listReq);
        if (list.isEmpty()) {
            return false;
        }
        if (list.size() > 1) {
            return true;
        } else {
            return !list.get(0).getSmsNotifyTemplateId().equals(smsNotifyTemplateId);
        }
    }

}

以及xhtml页面。我正在使用primefaces框架。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <ui:composition template="../../templates/layoutTemplate.xhtml" >
        <ui:define name="title">SMS Notify Template Configuration</ui:define>
        <ui:define name="featureName">SMS Notify Template Configuration</ui:define>
        <ui:define name="content">
            <h:form id="frmSmsNotifyTemplate">
                <p:dataTable var="tabSmsNotifyTemplate"
                             id="smsNotifyTemplateList"
                             value="#{smsNotifyTemplateController.listSmsNotifyTemplate}"
                             selection="#{smsNotifyTemplateController.selectedSmsNotifyTemplates}"
                             rowsPerPageTemplate="5,10,15,20,50"
                             paginatorPosition="bottom"
                             paginator="true"
                             rows="10"
                             paginatorAlwaysVisible="false"
                             sortMode="single"
                             sortBy="#{tabSmsNotifyTemplate.smsNotifyTemplateId}"
                             rowKey="#{tabSmsNotifyTemplate.smsNotifyTemplateId}" >
                    <p:column selectionMode="multiple" style="width:16px;text-align:center" />
                    <p:ajax event="toggleSelect" update="@([id$=btnEdit]) @([id$=btnDelete])" />
                    <p:ajax event="rowSelect" update="@([id$=btnEdit]) @([id$=btnDelete])" />
                    <p:ajax event="rowSelectCheckbox" update="@([id$=btnEdit]) @([id$=btnDelete])" />
                    <p:ajax event="rowUnselectCheckbox" update="@([id$=btnEdit]) @([id$=btnDelete])" />
                    <p:column headerText="ID" style="width: 100px;">
                        <h:outputText value="#{tabSmsNotifyTemplate.smsNotifyTemplateId}" />
                    </p:column>
                    <p:column headerText="Message Template" style="width: 100px;" sortBy="#{tabSmsNotifyTemplate.messageTemplate}">
                        <h:outputText value="#{tabSmsNotifyTemplate.messageTemplate}" />
                    </p:column>
                    <p:column headerText="SMS Template Code" sortBy="#{tabSmsNotifyTemplate.smsTemplateCode}">
                        <h:outputText value="#{tabSmsNotifyTemplate.smsTemplateCode}" />
                    </p:column>
                    <p:column headerText="Language" sortBy="#{tabSmsNotifyTemplate.langId.nationality}">
                        <h:outputText value="#{tabSmsNotifyTemplate.langId.nationality}" />
                    </p:column>
                    <p:column headerText="Comments" sortBy="#{tabSmsNotifyTemplate.comments}">
                        <h:outputText value="#{tabSmsNotifyTemplate.comments}" />
                    </p:column>
                    <f:facet name="footer">
                        <div align="left">
                            <span class="vt-button">
                                <p:commandLink
                                    action="#{smsNotifyTemplateController.prepareInsert()}"
                                    process="smsNotifyTemplateList"
                                    update="@form"
                                    resetValues="true"
                                    style="margin-right:30px;border: none">
                                    <p:graphicImage style="width:10px;height:10px;"
                                                    value="/resources/themes/images/icon-add.png"/>
                                    <span class="vt-button-text">
                                        <h:outputText value="#{lang['common.button.add']}"/>
                                    </span>
                                    <f:setPropertyActionListener
                                        target="#{smsNotifyTemplateController.formStatus}"
                                        value="#{vpcrfConst.BTN_ADD}"/>
                                </p:commandLink>
                                <p:commandLink
                                    id="btnEdit"
                                    action="#{smsNotifyTemplateController.prepareEdit()}"
                                    process="smsNotifyTemplateList"
                                    update="@form"
                                    disabled="#{smsNotifyTemplateController.selectedSmsNotifyTemplates.size()&gt;1 or smsNotifyTemplateController.selectedSmsNotifyTemplates==null or smsNotifyTemplateController.selectedSmsNotifyTemplates.size()==0}"
                                    resetValues="true"
                                    style="margin-right:30px;border: none">
                                    <p:graphicImage style="width:10px;height:10px;"
                                                    value="/resources/themes/images/icon-edit.png"/>
                                    <span class="vt-button-text">
                                        <h:outputText value="#{lang['common.button.edit']}"/>
                                    </span>
                                    <f:setPropertyActionListener
                                        target="#{smsNotifyTemplateController.formStatus}"
                                        value="#{vpcrfConst.BTN_EDIT}"/>
                                </p:commandLink>
                                <p:commandLink
                                    id="btnDelete"
                                    action="#{smsNotifyTemplateController.delete()}"
                                    immediate="true"
                                    update="@form"
                                    disabled="#{smsNotifyTemplateController.selectedSmsNotifyTemplates.size()==0 or smsNotifyTemplateController.selectedSmsNotifyTemplates==null}"
                                    resetValues="true"
                                    style="margin-right:30px;border: none">
                                    <p:graphicImage style="width:10px;height:10px;"
                                                    value="/resources/themes/images/icon-delete.png"/>
                                    <span class="vt-button-text">
                                        <h:outputText value="#{lang['common.button.delete']}"/>
                                    </span>
                                    <p:confirm header="Delete" message="Are you sure? (Ok/Cancel)" icon="ui-icon-alert" />
                                </p:commandLink>
                            </span>
                        </div>
                    </f:facet>
                </p:dataTable>
                <p:growl id="testMsg" showSummary="false" showDetail="true" autoUpdate="true" sticky="true" />
                <p:focus context="editPanel"/>
                <p:fieldset legend="SMS Notify Template Detail" rendered="#{smsNotifyTemplateController.smsNotifyTemplate!=null}">
                    <h:panelGrid id="editPanel"
                                 columnClasses="vocs-120, vocs-300"
                                 columns="2" rendered="#{smsNotifyTemplateController.smsNotifyTemplate!=null}">
                        <p:outputLabel for="smsID" value="ID" />
                        <p:inputText id="smsID"
                                     value="#{smsNotifyTemplateController.smsNotifyTemplate.smsNotifyTemplateId}"
                                     required="true"
                                     maxlength="15"
                                     disabled="true"
                                     style="min-width: 300px;"/>
                        <p:outputLabel for="messTemplate" value="Message Template" />
                        <p:inputText id="messTemplate"
                                     value="#{smsNotifyTemplateController.smsNotifyTemplate.messageTemplate}"
                                     required="true"
                                     maxlength="60"
                                     style="min-width: 300px;"/>
                        <p:outputLabel for="langId" value="SMS Notify Template" />
                        <p:selectOneMenu id="langId" 
                                         required="true"
                                         value="#{smsNotifyTemplateController.smsNotifyTemplate.langId.langId}"
                                         style="width: 306px;">
                            <f:selectItem itemLabel="Select Language"
                                          itemDisabled="true" 
                                          noSelectionOption="true"/>
                            <f:selectItems value="#{smsNotifyTemplateController.listLang}"
                                           var="l"
                                           itemLabelEscaped="true"
                                           itemValue="#{l.langId}" 
                                           itemLabel="#{l.nationality}" />
                        </p:selectOneMenu>
                        <p:outputLabel for="templateCode" value="Template Code" />
                        <p:inputTextarea id="templateCode"
                                         value="#{smsNotifyTemplateController.smsNotifyTemplate.smsTemplateCode}"
                                         required="true"
                                         maxlength="10"
                                         style="min-width: 300px;"/>
                        <p:outputLabel for="comments" value="Comments" />
                        <p:inputTextarea id="comments"
                                         value="#{smsNotifyTemplateController.smsNotifyTemplate.comments}"
                                         required="false"
                                         maxlength="10"
                                         style="min-width: 300px;"/>
                        <div />
                        <h:panelGroup>
                            <p:commandButton
                                value="OK"
                                process="editPanel"
                                rendered="#{smsNotifyTemplateController.formStatus==vpcrfConst.BTN_ADD}"
                                action="#{smsNotifyTemplateController.insert()}"
                                update="smsNotifyTemplateList,editPanel,@form" />
                            <p:commandButton rendered="#{smsNotifyTemplateController.formStatus==vpcrfConst.BTN_ADD}"
                                             value="#{lang['common.button.reset']}"
                                             immediate="true">
                                <p:ajax update="smsID,messTemplate,langId,templateCode,comments" resetValues="true" />
                            </p:commandButton>
                            <p:commandButton
                                value="OK"
                                rendered="#{smsNotifyTemplateController.formStatus==vpcrfConst.BTN_EDIT}"
                                action="#{smsNotifyTemplateController.update()}"
                                update="smsNotifyTemplateList,editPanel,@form" />
                            <p:commandButton rendered="#{smsNotifyTemplateController.formStatus==vpcrfConst.BTN_EDIT}"
                                             value="#{lang['common.button.reset']}"
                                             immediate="true"
                                             action="#{smsNotifyTemplateController.clearInput()}"
                                             update="smsID,messTemplate,langId,templateCode,comments"
                                             resetValues="true"/>     
                            <p:commandButton
                                value="#{lang['common.button.cancel']}"
                                action="#{smsNotifyTemplateController.reset()}"
                                immediate="true"
                                update="@form"/>
                        </h:panelGroup>
                    </h:panelGrid>
                </p:fieldset>
            </h:form>
        </ui:define>
    </ui:composition>
</html>

共有1个答案

麹凯捷
2023-03-14

文件解释了这种差异deleteInBatch()执行以下操作:

删除批处理中的给定实体,这意味着它将创建单个查询。假设我们将在调用后清除实体管理器。

而< code>delete()执行以下操作:

删除给定的实体。

因此,第一个将执行删除JPQL查询,如

delete from SomeEntity e where e.id in :ids

而第二个将遍历实体并调用

entityManager.remove(entity)

无论您的实体是否有外键,两者都应该工作。第二个将应用级联,而第一个不会。如果不了解您的代码,就不可能知道为什么会有这个问题。

 类似资料:
  • 问题内容: 我们正在使用SQL Server 2008,其中一项要求是在为系统定义的实体上具有可扩展的用户定义属性。例如,我们可能有一个名为Doctor的实体,我们希望系统管理员能够定义通常不在系统中的其他属性。这些属性很可能是链接父表或联接表的查询条件所必需的。 将有定义属性(名称,描述,类型)等的表,但是我的问题是实际数据值的存储。 我不是DBA(只是一个假装成程序员的DBA),但我首先想到的

  • 在Spring构建存储库时,在我的存储库界面中,我使用以下内容扩展它 扩展CrudRepository 但是我注意到JpaRepository的使用,请参阅下面的示例

  • 我有一个数据已经保存在我的数据库基于我的存储库和服务。我想保存另一个数据与邮递员只改变播放器id。但它不是创建一个新的实体数据。它更新现有的实体数据。我的问题是如何更新一个数据由我的服务当它找到一个现有的id。但当它找到一个新的id将保存一个新的数据到数据库。 这是我的回购: 这是我的服务:

  • 我正在尝试编写一个扩展,在其中我可以将请求和响应存储在数据库中。我扩展了PostActionServe,现在有两个问题 > 启动模拟服务器后,我向 http://localhost:8089/__admin/mappings 提交了发布请求,但都未调用 doAction 或 doGlobalAction。 现在,如果我到达终点/一些/东西,那么只有全局动作被调用。 我希望当我向mappings A

  • 为了简单起见,假设我想使用Azure REST API从特定存储库中的所有秘密中使用秘密名称和秘密值构建一个字典。 谢谢你。

  • 我需要帮助删除连接到vs代码的存储库。实际上,我想添加一个与现有存储库不同的新存储库。 场景:“repo1”存在于vs代码中。我需要添加一个新的,即“repo2”,并从vs代码中删除旧的“repo1”。