选择带有多栏的多对多

时间:2019-01-22 16:27:23

标签: hibernate jpa spring-data-jpa

我在两个表之间有很多关系:

enter image description here

流程是这样的:

创建包->创建dataSet [将其链接到包]-> dataSet具有n个结构-> n到n个转换(包-> n TRANSFORMATION)。

我的问题是,当我选择(在我使用转换链接包装和使用结构转换)后,转换得到空白结构[]

这是我的代码(将包与转换链接在一起,并与结构保持转换)

Optional<Package> aPackage = packagePersistenceService.findById(tranformationPackageStructure.getPackageID());
    Optional<Structure> structureIn = structureService.findById(tranformationPackageStructure.getStructureInID());

    if (aPackage.isPresent() && structureIn.isPresent()){
        TransformationStructInOutDomain transformationStructInOutDomain = new TransformationStructInOutDomain();


        //Create struct out
        Optional<Structure> structureOut = structureService.save(tranformationPackageStructure.getStructureOut());

        /*
         *  PACKAGE - TRANSFORMATION
         *****/
            //-- Save transformation
            Transformation transformation = tranformationPackageStructure.getTransformation();
            transformation.setaPackage(aPackage.get());
            Transformation savedTransformation = transformationRepository.save(transformation);
            aPackage.get().getTransformations().add(transformation);
            packagePersistenceService.save(aPackage.get());

        /*
         *  TRANSFORMATION - STRUCTURE
         *****/
            //Link to struct in
            transformationStructureService.save(savedTransformation, structureIn.get());
            structureIn.get().getTransformations().add(new TransformationStructure(structureIn.get(), savedTransformation, STRUCT_IN));
            structureService.save(structureIn.get());

            //Link to structure out
            transformationStructureService.save(savedTransformation, structureOut.get());
            structureOut.get().getTransformations().add(new TransformationStructure(structureOut.get(), savedTransformation, STRUCT_OUT));
            structureService.save(structureOut.get());

        return Optional.of(transformationStructInOutDomain);
    }

获得全部结果:

enter image description here 谢谢。

0 个答案:

没有答案