Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Can';不能使用hibernate删除实体_Java_Entity Framework_Hibernate_Spring Data_Spring Data Jpa - Fatal编程技术网

Java Can';不能使用hibernate删除实体

Java Can';不能使用hibernate删除实体,java,entity-framework,hibernate,spring-data,spring-data-jpa,Java,Entity Framework,Hibernate,Spring Data,Spring Data Jpa,我无法使用Spring数据Jpa(hibernate)从数据库中删除实体。当我从JpaRepository调用hibernate的delete方法时,没有错误或异常,但我的FactureSortie实体没有被删除。 这是我的模型: 制造商,制造商超类出动架次: 制造商架次: 以下是我的FactoreSortiesService,它称为FactoreSortiedao: package be.afelio.GEDFacture.business.impl; 导入java.util.ArrayLis

我无法使用Spring数据Jpa(hibernate)从数据库中删除实体。当我从JpaRepository调用hibernate的delete方法时,没有错误或异常,但我的FactureSortie实体没有被删除。 这是我的模型:

制造商,制造商超类出动架次:

制造商架次:

以下是我的FactoreSortiesService,它称为FactoreSortiedao:

package be.afelio.GEDFacture.business.impl;
导入java.util.ArrayList;
导入java.util.Date;
导入java.util.List;
导入org.dozer.DozerBeanMapper;
导入org.dozer.Mapper;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.data.domain.PageRequest;
导入org.springframework.stereotype.Component;
导入org.springframework.transaction.annotation.Transactional;
导入be.afelio.GEDFacture.business.ClientService;
导入be.afelio.GEDFacture.business.CommandeService;
进口be.afelio.GEDFacture.business.FactoryService;
进口be.afelio.GEDFacture.business.Factory或Service;
导入be.afelio.GEDFacture.business.ProjectService;
进口be.afelio.GEDFacture.dao.factoreSortiedao;
导入be.afelio.GEDFacture.dto.ClientDto;
进口be.afelio.GEDFacture.dto.factures或tiedto;
导入be.afelio.GEDFacture.dto.projetdo;
导入be.afelio.GEDFacture.entities.Client;
进口be.afelio.GEDFacture.entities.Factory架次;
导入be.afelio.GEDFacture.entities.Projet;
导入be.afelio.GEDFacture.tools.DtoConverter;
@组成部分
公共类FactureSortieServiceImpl实现FactureSortieService{
@自动连线
私人制造商制造商;
@自动连线
私人项目服务项目服务;
@自动连线
私人制造服务;
@自动连线
私人命令服务命令服务;
@自动连线
私人客户服务;
私有映射器映射器=新的DozerBeanMapper();
/**
*@param断裂
*
*调用不同服务的add方法将数据添加到
*调用createProjet在数据库中添加项目,然后
*获取factureService的新projectid调用add以添加
*在数据库中制作并获取新的factureid调用addCommande
*添加一条命令并获取新的
*commandeid将制作的id设置为null,因为它处于休眠状态
*不处理非空id以添加保存制作并获取
*它。
*/
@凌驾
@交易的
公共生产商或添加生产商(生产商或添加生产商){
试一试{
制造商出动架次=D到转换器转换制造商到(制造商);
出动.getFacture().set插补(projetService.createProjet(出动.getFacture().get插补());
setIdClient(clientService.createClient(sortie.getIdClient());
出动.setFacture(factureService.add(出动.getFacture());
sortie.setIdCommande(commandeService.addCommande(sortie.getIdCommande());
//facture.setIdFacture(fa.getFacture().getIdFacture());
出动次数=制造商出动次数。保存(出动次数);
返回数据转换器转换制造(架次);
}捕获(例外e){
e、 printStackTrace();
}
返回null;
}
@交易的
@凌驾
公共列表FindAll(整版页,整版大小){
整数运算=0;
int taille=size==0?10:大小;
数字运算=页数/尾数;
List factures=factureSortieDAO.findAll(新页面请求(数值运算,taille)).getContent();
List factoresdto=new ArrayList();
工厂出动架次:工厂{
制造商添加(DtoConverter.convertFacture(制造商));
}
返回制造地;
}
@凌驾
公共列表查找(Date dateStart、Date dateEnd、Integer pieceNumberStart、Integer PieceNumberRend、,
客户端到idClient,项目到projet,双MontantVacStart,双MontantVacEnd,列出UUID,
int first、int max、字符串排序字段、字符串排序器){
映射器映射器=新的DozerBeanMapper();
列举事实;
Client=null;
if(idClient!=null)
client=mapper.map(idClient,client.class);
Projet项目=null;
if(projet!=null)
project=mapper.map(projet,projet.class);
factures=this.factureSortieDAO.findWithCriterias(dateStart、dateEnd、pieceNumberStart、PieceNumberRend、client、,
项目,蒙塔特瓦茨特启动,蒙塔特瓦森德,乌伊兹,第一,马克斯,索特菲尔德,索托德);
List factoresdto=new ArrayList();
工厂出动架次:工厂{
制造商添加(DtoConverter.convertFacture(制造商));
}
返回制造地;
}
@凌驾
公共长计数(Date dateStart、Date dateEnd、Integer pieceNumberStart、Integer PieceNumberRend、,
客户端到idClient、项目到projet、双MontantVacStart、双MontantVacEnd、列表UUID){
Client=null;
if(idClient!=null)
client=mapper.map(idClient,client.class);
Projet项目=null;
if(projet!=null)
project=mapper.map(projet,projet.class);
返回此.factureSortieDAO.Count(日期开始、日期结束、计件编号开始、计件编号趋势、客户机、项目、,
MontantVaceStart、MontantVacend、UUIDs);
}
@凌驾
公共长计数(){
返回此.factureSortieDAO.count();
}
@凌驾
@事务(只读=假)
公共无效删除制作(制作至f){
制造商架次制造商=DTO转换器。转换器制造商DTO(f);
facture=this.factureSortieDAO.findOne(facture.getIdFacture());
此.factureSortieDAO.delete(facture);
删除(facture.getFacture());
}
}
这是我的制造商Sortiedao:

包be.afelio.GEDF
package be.afelio.GEDFacture.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
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.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author johan
 */
@Entity
@Table(name = "facture")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Facture.findAll", query = "SELECT f FROM Facture f")
    , @NamedQuery(name = "Facture.findByIdFacture", query = "SELECT f FROM Facture f WHERE f.idFacture = :idFacture")
    , @NamedQuery(name = "Facture.findByMontantHTVA", query = "SELECT f FROM Facture f WHERE f.montantHTVA = :montantHTVA")
    , @NamedQuery(name = "Facture.findByMontantTVAC", query = "SELECT f FROM Facture f WHERE f.montantTVAC = :montantTVAC")
    , @NamedQuery(name = "Facture.findByMontantTVA", query = "SELECT f FROM Facture f WHERE f.montantTVA = :montantTVA")
    , @NamedQuery(name = "Facture.findByDateFacturation", query = "SELECT f FROM Facture f WHERE f.dateFacturation = :dateFacturation")
    , @NamedQuery(name = "Facture.findByNumerocomptable", query = "SELECT f FROM Facture f WHERE f.numerocomptable = :numerocomptable")
    , @NamedQuery(name = "Facture.findByUuid", query = "SELECT f FROM Facture f WHERE f.uuid = :uuid")
    , @NamedQuery(name = "Facture.findByNumeroPiece", query = "SELECT f FROM Facture f WHERE f.numeroPiece = :numeroPiece")
    , @NamedQuery(name = "Facture.findByValidee", query = "SELECT f FROM Facture f WHERE f.validee = :validee")})
public class Facture implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_Facture")
    private Integer idFacture;
    @Basic(optional = false)
    @Column(name = "Montant_HTVA")
    private double montantHTVA;
    @Basic(optional = false)
    @Column(name = "Montant _TVAC")
    private double montantTVAC;
    @Basic(optional = false)
    @Column(name = "Montant_TVA")
    private double montantTVA;
    @Basic(optional = false)
    @Column(name = "Date_Facturation")
    @Temporal(TemporalType.DATE)
    private Date dateFacturation;
    @Column(name = "Numero_comptable")
    private Integer numerocomptable;
    @Basic(optional = false)
    @Column(name = "uuid")
    private String uuid;
    @Basic(optional = false)
    @Column(name = "numero_piece")
    private int numeroPiece;
    @Column(name = "validee")
    private Boolean validee;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "facture")
    private FactureSortie factureSortie;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "facture")
    private FactureEntree factureEntree;
    @JoinColumn(name = "imputation", referencedColumnName = "Imputation")
    @ManyToOne
    private Projet imputation;

    public Facture() {
    }

    public Facture(Integer idFacture) {
        this.idFacture = idFacture;
    }

    public Facture(Integer idFacture, double montantHTVA, double montantTVAC, double montantTVA, Date dateFacturation, String uuid, int numeroPiece) {
        this.idFacture = idFacture;
        this.montantHTVA = montantHTVA;
        this.montantTVAC = montantTVAC;
        this.montantTVA = montantTVA;
        this.dateFacturation = dateFacturation;

        this.uuid = uuid;
        this.numeroPiece = numeroPiece;
    }

    public Integer getIdFacture() {
        return idFacture;
    }

    public void setIdFacture(Integer idFacture) {
        this.idFacture = idFacture;
    }

    public double getMontantHTVA() {
        return montantHTVA;
    }

    public void setMontantHTVA(double montantHTVA) {
        this.montantHTVA = montantHTVA;
    }

    public double getMontantTVAC() {
        return montantTVAC;
    }

    public void setMontantTVAC(double montantTVAC) {
        this.montantTVAC = montantTVAC;
    }

    public double getMontantTVA() {
        return montantTVA;
    }

    public void setMontantTVA(double montantTVA) {
        this.montantTVA = montantTVA;
    }

    public Date getDateFacturation() {
        return dateFacturation;
    }

    public void setDateFacturation(Date dateFacturation) {
        this.dateFacturation = dateFacturation;
    }


    public Integer getNumerocomptable() {
        return numerocomptable;
    }

    public void setNumerocomptable(Integer numerocomptable) {
        this.numerocomptable = numerocomptable;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public int getNumeroPiece() {
        return numeroPiece;
    }

    public void setNumeroPiece(int numeroPiece) {
        this.numeroPiece = numeroPiece;
    }

    public Boolean getValidee() {
        return validee;
    }

    public void setValidee(Boolean validee) {
        this.validee = validee;
    }

    public FactureSortie getFactureSortie() {
        return factureSortie;
    }

    public void setFactureSortie(FactureSortie factureSortie) {
        this.factureSortie = factureSortie;
    }

    public FactureEntree getFactureEntree() {
        return factureEntree;
    }

    public void setFactureEntree(FactureEntree factureEntree) {
        this.factureEntree = factureEntree;
    }

    public Projet getImputation() {
        return imputation;
    }

    public void setImputation(Projet imputation) {
        this.imputation = imputation;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFacture != null ? idFacture.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 Facture)) {
            return false;
        }
        Facture other = (Facture) object;
        if ((this.idFacture == null && other.idFacture != null) || (this.idFacture != null && !this.idFacture.equals(other.idFacture))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Models.Facture[ idFacture=" + idFacture + " ]";
    }

}
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package be.afelio.GEDFacture.entities;

import java.io.Serializable;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

/**
 *
 * @author johan
 */
@Entity
@Table(name = "facture_sortie")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "FactureSortie.findAll", query = "SELECT f FROM FactureSortie f")
    , @NamedQuery(name = "FactureSortie.findByIdFacture", query = "SELECT f FROM FactureSortie f WHERE f.idFacture = :idFacture")})
public class FactureSortie implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
//  @GeneratedValue(strategy = GenerationType.IDENTITY)
//  @Basic(optional = false)
  @GeneratedValue(generator="sharedKeyFactureSort")
  @GenericGenerator(name="sharedKeyFactureSort", strategy = "foreign", parameters = @Parameter(name="property", value="facture"))
  @Column(name = "id_facture")
    private Integer idFacture;
    @JoinColumn(name = "id_client", referencedColumnName = "id_client")
    @ManyToOne(optional = false)
    private Client idClient;
    @JoinColumn(name = "id_commande", referencedColumnName = "id_commande")
    @ManyToOne(optional = false)
    private Commande idCommande;
    @JoinColumn(name = "id_facture", referencedColumnName = "id_Facture", insertable = false, updatable = true)
    @OneToOne(optional = false)
    private Facture facture;
    @JoinColumn(name = "id_prestation", referencedColumnName = "id_prestation")
    @ManyToOne
    private Prestation idPrestation;
    @JoinColumn(name = "id_type_vente", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private TypeVente idTypeVente;

    public FactureSortie() {
    }

    public FactureSortie(Integer idFacture) {
        this.idFacture = idFacture;
    }

    public Integer getIdFacture() {
        return idFacture;
    }

    public void setIdFacture(Integer idFacture) {
        this.idFacture = idFacture;
    }

    public Client getIdClient() {
        return idClient;
    }

    public void setIdClient(Client idClient) {
        this.idClient = idClient;
    }

    public Commande getIdCommande() {
        return idCommande;
    }

    public void setIdCommande(Commande idCommande) {
        this.idCommande = idCommande;
    }

    public Facture getFacture() {
        return facture;
    }

    public void setFacture(Facture facture) {
        this.facture = facture;
    }

    public Prestation getIdPrestation() {
        return idPrestation;
    }

    public void setIdPrestation(Prestation idPrestation) {
        this.idPrestation = idPrestation;
    }

    public TypeVente getIdTypeVente() {
        return idTypeVente;
    }

    public void setIdTypeVente(TypeVente idTypeVente) {
        this.idTypeVente = idTypeVente;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idFacture != null ? idFacture.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 FactureSortie)) {
            return false;
        }
        FactureSortie other = (FactureSortie) object;
        if ((this.idFacture == null && other.idFacture != null) || (this.idFacture != null && !(this.idFacture == other.idFacture))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Models.FactureSortie[ idFacture=" + idFacture + " ]";
    }

}
 package be.afelio.GEDFacture.business.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import be.afelio.GEDFacture.business.ClientService;
import be.afelio.GEDFacture.business.CommandeService;
import be.afelio.GEDFacture.business.FactureService;
import be.afelio.GEDFacture.business.FactureSortieService;
import be.afelio.GEDFacture.business.ProjectService;
import be.afelio.GEDFacture.dao.FactureSortieDAO;
import be.afelio.GEDFacture.dto.ClientDto;
import be.afelio.GEDFacture.dto.FactureSortieDto;
import be.afelio.GEDFacture.dto.ProjetDto;
import be.afelio.GEDFacture.entities.Client;
import be.afelio.GEDFacture.entities.FactureSortie;
import be.afelio.GEDFacture.entities.Projet;
import be.afelio.GEDFacture.tools.DtoConverter;

@Component
public class FactureSortieServiceImpl implements FactureSortieService {
    @Autowired
    private FactureSortieDAO factureSortieDAO;
    @Autowired
    private ProjectService projetService;

    @Autowired
    private FactureService factureService;
    @Autowired
    private CommandeService commandeService;
    @Autowired
    private ClientService clientService;
    private Mapper mapper = new DozerBeanMapper();

    /**
     * @param facture
     *
     *            call the add method of different services to add data in
     *            database. call createProjet to add a project in database and
     *            get the new projectid call add of factureService to add a
     *            facture in database and get the new factureid call addCommande
     *            of the commandeService to add a commande and get the new
     *            commandeid Set the id of the facture to null because hibernate
     *            doesn't handle the non-null id to add save the facture and get
     *            it.
     */

    @Override
    @Transactional
    public FactureSortieDto addFacture(FactureSortieDto facture) {

        try {
            FactureSortie sortie = DtoConverter.convertFactureDto(facture);
            sortie.getFacture().setImputation(projetService.createProjet(sortie.getFacture().getImputation()));
            sortie.setIdClient(clientService.createClient(sortie.getIdClient()));
            sortie.setFacture(factureService.add(sortie.getFacture()));
            sortie.setIdCommande(commandeService.addCommande(sortie.getIdCommande()));

            // facture.setIdFacture(fa.getFacture().getIdFacture());

            sortie = factureSortieDAO.save(sortie);
            return DtoConverter.convertFacture(sortie);

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    @Transactional
    @Override
    public List<FactureSortieDto> FindAll(int page, int size) {

        int numeroPage = 0;
        int taille = size == 0 ? 10 : size;
        numeroPage = page / taille;
        List<FactureSortie> factures = factureSortieDAO.findAll(new PageRequest(numeroPage, taille)).getContent();

        List<FactureSortieDto> facturesDto = new ArrayList<>();

        for (FactureSortie facture : factures) {
            facturesDto.add(DtoConverter.convertFacture(facture));

        }

        return facturesDto;
    }

    @Override
    public List<FactureSortieDto> find(Date dateStart, Date dateEnd, Integer pieceNumberStart, Integer pieceNumberEnd,
            ClientDto idClient, ProjetDto projet, Double montantTVACStart, Double montantTVACEnd, List<String> UUIDs,
            int first, int max, String sortField, String sortOrder) {
        Mapper mapper = new DozerBeanMapper();
        List<FactureSortie> factures;
        Client client=null;
        if(idClient!=null)
         client= mapper.map(idClient, Client.class);
        Projet project=null;
        if(projet!=null)
            project = mapper.map(projet, Projet.class);


        factures = this.factureSortieDAO.findWithCriterias(dateStart, dateEnd, pieceNumberStart, pieceNumberEnd, client,
                project, montantTVACStart, montantTVACEnd, UUIDs, first, max, sortField, sortOrder);

        List<FactureSortieDto> facturesDto = new ArrayList<>();

        for (FactureSortie facture : factures) {
            facturesDto.add(DtoConverter.convertFacture(facture));

        }

        return facturesDto;
    }

    @Override
    public long count(Date dateStart, Date dateEnd, Integer pieceNumberStart, Integer pieceNumberEnd,
            ClientDto idClient, ProjetDto projet, Double montantTVACStart, Double montantTVACEnd, List<String> UUIDs) {
        Client client=null;
        if(idClient!=null)
         client= mapper.map(idClient, Client.class);
        Projet project=null;
        if(projet!=null)
            project = mapper.map(projet, Projet.class);

        return this.factureSortieDAO.Count(dateStart, dateEnd, pieceNumberStart, pieceNumberEnd, client, project,
                montantTVACStart, montantTVACEnd, UUIDs);
    }

    @Override
    public long countAll() {
        return this.factureSortieDAO.count();
    }

    @Override
    @Transactional(readOnly=false)
    public void deleteFacture(FactureSortieDto f) {
        FactureSortie facture = DtoConverter.convertFactureDto(f);
        facture=this.factureSortieDAO.findOne(facture.getIdFacture());
        this.factureSortieDAO.delete(facture);
        this.factureService.delete(facture.getFacture());

    }
}
package be.afelio.GEDFacture.dao;



import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import org.springframework.data.jpa.repository.JpaRepository;

import org.springframework.transaction.annotation.Transactional;

import be.afelio.GEDFacture.entities.FactureSortie;

public interface FactureSortieDAO extends JpaRepository<FactureSortie, Integer>,FactureSortieDAOCustom{
      List<FactureSortie> findAll(Sort sort);





     }