原因:javax.persistence.EntityExistsException:具有相同标识符值的另一个对象已与会话关联

时间:2019-04-01 12:58:36

标签: java spring-boot jpa persistence spring-transactions

当我要保存包含“ DatosMaestro”实体的OneToMany关系的“ TablasMaestra”实体时,我遇到问题。我创建对象MasterTables并插入新的“ MasterData”实体列表。

所有“ DatosMaestro”对象的ID为null,因为它们是新对象。

当我调用saveTablasMaestra方法时,就是我 返回异常:

Caused by: javax.persistence.EntityExistsException: A different object with the same identifier value was already associated with the session : [com.soprasteria.mater.entity.DatosMaestro#com.soprasteria.mater.entity.DatosMaestroPK@3fd1]
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:118)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
    at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)

我附上了实体和服务的代码。


package com.soprasteria.mater.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

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.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.PrePersist;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;


/**
 * The persistent class for the tablas_maestras database table.
 * 
 */
@Entity
@Table(name="tablas_maestras")
@NamedQuery(name="TablasMaestra.findAll", query="SELECT t FROM TablasMaestra t")
public class TablasMaestra implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(unique=true, nullable=false)
    private int id;

    @Column(name="descripcion_castellano", length=255)
    private String descripcionCastellano;

    @Column(name="descripcion_catalan", length=255)
    private String descripcionCatalan;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_baja")
    private Date fechaBaja;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_creacion")
    private Date fechaCreacion;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_modificacion")
    private Date fechaModificacion;

    @Column(name="usuario_baja", length=45)
    private String usuarioBaja;

    @Column(name="usuario_creacion", length=45)
    private String usuarioCreacion;

    @Column(name="usuario_modificacion", length=45)
    private String usuarioModificacion;

    //bi-directional many-to-one association to DatosMaestro
    @OneToMany(mappedBy="tablasMaestra", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<DatosMaestro> datosMaestros;

    public TablasMaestra() {
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getDescripcionCastellano() {
        return this.descripcionCastellano;
    }

    public void setDescripcionCastellano(String descripcionCastellano) {
        this.descripcionCastellano = descripcionCastellano;
    }

    public String getDescripcionCatalan() {
        return this.descripcionCatalan;
    }

    public void setDescripcionCatalan(String descripcionCatalan) {
        this.descripcionCatalan = descripcionCatalan;
    }

    public Date getFechaBaja() {
        return this.fechaBaja;
    }

    public void setFechaBaja(Date fechaBaja) {
        this.fechaBaja = fechaBaja;
    }

    public Date getFechaCreacion() {
        return this.fechaCreacion;
    }

    public void setFechaCreacion(Date fechaCreacion) {
        this.fechaCreacion = fechaCreacion;
    }

    public Date getFechaModificacion() {
        return this.fechaModificacion;
    }

    public void setFechaModificacion(Date fechaModificacion) {
        this.fechaModificacion = fechaModificacion;
    }

    public String getUsuarioBaja() {
        return this.usuarioBaja;
    }

    public void setUsuarioBaja(String usuarioBaja) {
        this.usuarioBaja = usuarioBaja;
    }

    public String getUsuarioCreacion() {
        return this.usuarioCreacion;
    }

    public void setUsuarioCreacion(String usuarioCreacion) {
        this.usuarioCreacion = usuarioCreacion;
    }

    public String getUsuarioModificacion() {
        return this.usuarioModificacion;
    }

    public void setUsuarioModificacion(String usuarioModificacion) {
        this.usuarioModificacion = usuarioModificacion;
    }

    public List<DatosMaestro> getDatosMaestros() {
        return this.datosMaestros;
    }

    public void setDatosMaestros(List<DatosMaestro> datosMaestros) {
        this.datosMaestros = datosMaestros;
    }

    public DatosMaestro addDatosMaestro(DatosMaestro datosMaestro) {
        getDatosMaestros().add(datosMaestro);
        datosMaestro.setTablasMaestra(this);

        return datosMaestro;
    }

    public DatosMaestro removeDatosMaestro(DatosMaestro datosMaestro) {
        getDatosMaestros().remove(datosMaestro);
        datosMaestro.setTablasMaestra(null);

        return datosMaestro;
    }


   @PrePersist
   private void prePersiste() {
       for(DatosMaestro datosMaestro:this.datosMaestros) {
           if(datosMaestro.getId()==null) {
               datosMaestro.setId(new DatosMaestroPK());
           }
           datosMaestro.setTablasMaestra(this);
       }
   }


}


    private void cargaDatosMaestro(String tabla) {
        TablasMaestraDTO tablaMaestra = new TablasMaestraDTO();
        tablaMaestra.setDescripcionCastellano(tabla);
        tablaMaestra.setDescripcionCatalan(tabla);

        List<DatoMaestroDTO> listDatoMaestro= new ArrayList<DatoMaestroDTO>();
        for(int i=0;i<4;i++) {
            DatoMaestroDTO datoMaestro = new DatoMaestroDTO();
            datoMaestro.setDescripcionCastellano(tabla+i);
            datoMaestro.setDescripcionCatalan(tabla+ i +" cat");
            datoMaestro.setTablaMaestra(tablaMaestra);
            listDatoMaestro.add(datoMaestro);
        }
        tablaMaestra.setDatosMaestros(listDatoMaestro);

        tablaMaestra=insertTablaMaestra(tablaMaestra);




    }


    private TablasMaestraDTO insertTablaMaestra(TablasMaestraDTO tablaMaestra) {
        tablaMaestra.setFechaCreacion(new Date());
        tablaMaestra=tablasMaestraService.saveTablasMaestra(tablaMaestra);
        return tablaMaestra;
    }

/**
     * Graba en base de datos la entidad TablasMaestra
     * 
     * @param TablasMaestraDTO
     * @return TablasMaestraDTO
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public TablasMaestraDTO saveTablasMaestra(TablasMaestraDTO dto) {
        TablasMaestra entity = new ModelMapper().map(dto, TablasMaestra.class);
        entity=tablasMaestrasRepository.save(entity);
        if (entity != null) {
            dto = new ModelMapper().map(entity, TablasMaestraDTO.class);
        }
        return dto;
    }
package com.soprasteria.mater.entity;

import java.io.Serializable;
import javax.persistence.*;

/**
 * The primary key class for the datos_maestros database table.
 * 
 */
@Embeddable
public class DatosMaestroPK implements Serializable {
    //default serial version id, required for serializable classes.
    private static final long serialVersionUID = 1L;

    @Column(name="id", unique=true, nullable=false)
    private int id_pk;

    @Column(name="tablas_maestras_id_tabla", insertable=false, updatable=false, unique=true, nullable=false)
    private int tablasMaestrasIdTabla;

    public DatosMaestroPK() {
    }
    public int getId_pk() {
        return this.id_pk;
    }
    public void setId_pk(int id_pk) {
        this.id_pk = id_pk;
    }
    public int getTablasMaestrasIdTabla() {
        return this.tablasMaestrasIdTabla;
    }
    public void setTablasMaestrasIdTabla(int tablasMaestrasIdTabla) {
        this.tablasMaestrasIdTabla = tablasMaestrasIdTabla;
    }

    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof DatosMaestroPK)) {
            return false;
        }
        DatosMaestroPK castOther = (DatosMaestroPK)other;
        return 
            (this.id_pk == castOther.id_pk)
            && (this.tablasMaestrasIdTabla == castOther.tablasMaestrasIdTabla);
    }

    public int hashCode() {
        final int prime = 31;
        int hash = 17;
        hash = hash * prime + this.id_pk;
        hash = hash * prime + this.tablasMaestrasIdTabla;

        return hash;
    }
}
package com.soprasteria.mater.repository;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import com.soprasteria.mater.entity.DatosMaestro;
import com.soprasteria.mater.entity.TablasMaestra;

public interface TablasMaestrasRepository extends CrudRepository<TablasMaestra, Integer>{
      @Query(value = "select count(*) from TablasMaestra tablasMaestra where tablasMaestra.id = ?1")
      long subtaskNumber(int datosMaestroId);

      @Query(value = "select max(tablasMaestra.id) from TablasMaestra tablasMaestra")
      long lastDatosMaestroId();

      @Query(value="select tablasMaestra from TablasMaestra tablasMaestra order by id desc")
      public List<DatosMaestro> findAllByOrderByCreatedOnDesc();
}

1 个答案:

答案 0 :(得分:0)

我进行了一些更改,以尝试不同的交易方式。我现在将代码传递给您,因为我正在执行测试,所以肯定会有不必要的事情。任何改进的建议都将受到欢迎。非常感谢你!

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
    private void cargaDatosMaestro(String tabla) {
        TablasMaestraDTO tablaMaestra = new TablasMaestraDTO();
        tablaMaestra.setDescripcionCastellano(tabla);
        tablaMaestra.setDescripcionCatalan(tabla);
        tablaMaestra=insertTablaMaestra(tablaMaestra);
        List<AreaDTO> areas = areaService.getAreas();
        for(int i=0;i<4;i++) {
            DatoMaestroDTO datoMaestro = new DatoMaestroDTO();
            datoMaestro.setDescripcionCastellano(tabla+i);
            datoMaestro.setDescripcionCatalan(tabla+ i +" cat");
            datoMaestro.setTablaMaestra(tablaMaestra);
            datoMaestro.setArea(areas.get(0));
            datoMaestroService.saveDatoMaestro(datoMaestro);;
        }

    }


    /**
     * Graba en base de datos la entidad DatoMaestro
     * 
     * @param DatoMaestroDTO
     */
    @Override
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
    public void saveDatoMaestro(DatoMaestroDTO dto) {
        DatosMaestro entity = new ModelMapper().map(dto, DatosMaestro.class);
//      TablasMaestra tablaTemp = null;
//      if(entity.getTablasMaestra()!=null) {
//          tablaTemp=entity.getTablasMaestra();
//          entity.setTablasMaestra(null);
//      }
        entity=datomaestroRepository.save(entity);
//      entity.setTablasMaestra(tablaTemp);
    }
package com.soprasteria.mater.entity;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;


/**
 * The persistent class for the datos_maestros database table.
 * 
 */
@Entity
@Table(name="datos_maestros")
@NamedQuery(name="DatosMaestro.findAll", query="SELECT d FROM DatosMaestro d")
public class DatosMaestro implements Serializable {
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private DatosMaestroPK id;

    @Column(name="descripcion_castellano", length=255)
    private String descripcionCastellano;

    @Column(name="descripcion_catalan", length=255)
    private String descripcionCatalan;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_baja")
    private Date fechaBaja;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_creacion")
    private Date fechaCreacion;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="fecha_modificacion")
    private Date fechaModificacion;

    private int orden;

    @Column(name="usuario_baja", length=45)
    private String usuarioBaja;

    @Column(name="usuario_creacion", length=45)
    private String usuarioCreacion;

    @Column(name="usuario_modificacion", length=45)
    private String usuarioModificacion;

    //bi-directional many-to-one association to Area
    @ManyToOne(fetch=FetchType.LAZY,cascade= CascadeType.ALL)
    @JoinColumn(name="area_id_area", nullable=false)
    private Area area;

    //bi-directional many-to-one association to TablasMaestra
    @ManyToOne(fetch=FetchType.LAZY,cascade= CascadeType.PERSIST)
    @JoinColumn(name="tablas_maestras_id_tabla", nullable=false, insertable=false, updatable=false)
    private TablasMaestra tablasMaestra;

    public DatosMaestro() {
    }

    public DatosMaestroPK getId() {
        return this.id;
    }

    public void setId(DatosMaestroPK id) {
        this.id = id;
    }

    public String getDescripcionCastellano() {
        return this.descripcionCastellano;
    }

    public void setDescripcionCastellano(String descripcionCastellano) {
        this.descripcionCastellano = descripcionCastellano;
    }

    public String getDescripcionCatalan() {
        return this.descripcionCatalan;
    }

    public void setDescripcionCatalan(String descripcionCatalan) {
        this.descripcionCatalan = descripcionCatalan;
    }

    public Date getFechaBaja() {
        return this.fechaBaja;
    }

    public void setFechaBaja(Date fechaBaja) {
        this.fechaBaja = fechaBaja;
    }

    public Date getFechaCreacion() {
        return this.fechaCreacion;
    }

    public void setFechaCreacion(Date fechaCreacion) {
        this.fechaCreacion = fechaCreacion;
    }

    public Date getFechaModificacion() {
        return this.fechaModificacion;
    }

    public void setFechaModificacion(Date fechaModificacion) {
        this.fechaModificacion = fechaModificacion;
    }

    public int getOrden() {
        return this.orden;
    }

    public void setOrden(int orden) {
        this.orden = orden;
    }

    public String getUsuarioBaja() {
        return this.usuarioBaja;
    }

    public void setUsuarioBaja(String usuarioBaja) {
        this.usuarioBaja = usuarioBaja;
    }

    public String getUsuarioCreacion() {
        return this.usuarioCreacion;
    }

    public void setUsuarioCreacion(String usuarioCreacion) {
        this.usuarioCreacion = usuarioCreacion;
    }

    public String getUsuarioModificacion() {
        return this.usuarioModificacion;
    }

    public void setUsuarioModificacion(String usuarioModificacion) {
        this.usuarioModificacion = usuarioModificacion;
    }

    public Area getArea() {
        return this.area;
    }

    public void setArea(Area area) {
        this.area = area;
    }

    public TablasMaestra getTablasMaestra() {
        return this.tablasMaestra;
    }

    public void setTablasMaestra(TablasMaestra tablasMaestra) {
        this.tablasMaestra = tablasMaestra;
    }

   @PrePersist
   private void prePersiste() {
       if (getId() == null) {
           setId(new DatosMaestroPK());
       }
       if(getTablasMaestra()!=null) {
           getId().setTablasMaestrasIdTabla(getTablasMaestra().getId());
       }
   }

}
package com.soprasteria.mater.entity;

import java.io.Serializable;
import javax.persistence.*;

/**
 * The primary key class for the datos_maestros database table.
 * 
 */
@Embeddable
public class DatosMaestroPK implements Serializable {
    //default serial version id, required for serializable classes.
    private static final long serialVersionUID = 1L;


    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id")
    private int id;

    @Column(name="tablas_maestras_id_tabla")
    private int tablasMaestrasIdTabla;

    public DatosMaestroPK() {
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getTablasMaestrasIdTabla() {
        return this.tablasMaestrasIdTabla;
    }
    public void setTablasMaestrasIdTabla(int tablasMaestrasIdTabla) {
        this.tablasMaestrasIdTabla = tablasMaestrasIdTabla;
    }

    public boolean equals(Object other) {
        if (this == other) {
            return true;
        }
        if (!(other instanceof DatosMaestroPK)) {
            return false;
        }
        DatosMaestroPK castOther = (DatosMaestroPK)other;
        return 
            (this.id == castOther.id)
            && (this.tablasMaestrasIdTabla == castOther.tablasMaestrasIdTabla);
    }

    public int hashCode() {
        final int prime = 31;
        int hash = 17;
        hash = hash * prime + this.id;
        hash = hash * prime + this.tablasMaestrasIdTabla;

        return hash;
    }
}

这是现在发布的例外:

org.springframework.dao.InvalidDataAccessApiUsageException: detached entity passed to persist: com.soprasteria.mater.entity.TablasMaestra; nested exception is org.hibernate.PersistentObjectException: detached entity passed to persist: com.soprasteria.mater.entity.TablasMaestra
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:280)
    at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:225)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
    at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
    at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
    at com.sun.proxy.$Proxy122.save(Unknown Source)
    at com.soprasteria.mater.service.DatoMaestroService.saveDatoMaestro(DatoMaestroService.java:63)
    at com.soprasteria.mater.service.DatoMaestroService$$FastClassBySpringCGLIB$$60d4a08a.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
    at com.soprasteria.mater.service.DatoMaestroService$$EnhancerBySpringCGLIB$$f07d9a5f.saveDatoMaestro(<generated>)
    at com.soprasteria.mater.CargaInicialTestService.cargaDatosMaestro(CargaInicialTestService.java:100)
    at com.soprasteria.mater.CargaInicialTestService.cargaInicialBDD(CargaInicialTestService.java:57)
    at com.soprasteria.mater.MaterApplicationTests.cargaInicial(MaterApplicationTests.java:75)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
    at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: com.soprasteria.mater.entity.TablasMaestra
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:124)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:806)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:773)
    at org.hibernate.jpa.event.internal.core.JpaPersistEventListener$1.cascade(JpaPersistEventListener.java:80)
    at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:467)
    at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:392)
    at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:193)
    at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:126)
    at org.hibernate.event.internal.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:414)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:252)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
    at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:782)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:767)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:304)
    at com.sun.proxy.$Proxy112.persist(Unknown Source)
    at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:490)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:377)
    at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:629)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:593)
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:578)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
    ... 53 more