具有收集字符串的DTO投影构造

时间:2018-07-25 14:58:49

标签: hibernate jpa spring-data-jpa

我将Spring Boot 2,jpa和hibernate一起使用。

我尝试与我的一个实体进行dto投影

@Entity
public class Factories extends BaseEntity {

    @Id
    @SequenceGenerator(name = "factories_id_seq", sequenceName = "factories_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "factories_id_seq")
    private Integer id;

    private String name;

    private String address;

    @OneToOne
    private Cities cities;

    @ManyToMany
    private Set<GranulateProducts> granulateProducts = new HashSet<>();

    @JsonIgnore
    @OneToMany(mappedBy = "factory", cascade = CascadeType.ALL, orphanRemoval = true)
    private final List<Machines> machines = new ArrayList<>();

    @ElementCollection
    private Collection<String> emails = new ArrayList<String>();

    private boolean generatedEmail;

    private boolean generation;

    private String phone;

    private String fax;

    private String director;

    ...
}

我的dto

public class FactoriesEditDto {

    private Integer id;

    private String name;

    private String address;

    private Integer citiesId;
    private String citiesName;

    private List<Integer> machinesId = new ArrayList<>();

    private List<String> emails = new ArrayList<>();

    private boolean generatedEmail;

    private boolean generation;

    private String phone;

    private String fax;

    private String director;

    public FactoriesEditDto(Integer id, String name, String address, Cities cities, List<Machines> machines, Collection<String> emails, boolean generatedEmail, boolean generation, String phone, String fax, String director) {
        this.id = id;
        this.name = name;
        this.address = address;

        if (cities != null) {
            this.citiesId = cities.getId();
            this.citiesName = cities.getName();
        }

        machines.stream().forEach(machine -> machinesId.add(machine.getId()));

        this.emails = (List<String>) emails;
        this.generatedEmail = generatedEmail;
        this.generation = generation;
        this.phone = phone;
        this.fax = fax;
        this.director = director;
    }

    ...
}   


public interface FactoriesRepository extends JpaRepository<Factories, Integer> {

public FactoriesEditDto findDtoedById(Integer id);

}

当我运行并尝试进行转换时,我得到了

  

org.hibernate.hql.internal.ast.QuerySyntaxException:无法找到   类[com.lcm.dto.FactoriesEditDto]上的适当构造函数。   预期参数为:int,java.lang.String,java.lang.String,   com.lcm.model.Cities,com.lcm.model.Machines,java.lang.String,   布尔值,布尔值,java.lang.String,java.lang.String,   java.lang.String [

     

选择新的com.lcm.dto.FactoriesEditDto(generateAlias0.id,     generateAlias0.name,generatedAlias0.address,     generateAlias0。城市,机器,电子邮件,     generateAlias0.GeneratedEmail,generateAlias0.generation,     generateAlias0.phone,generateAlias0.fax,     com.lcm.model.Factories中的generateAlias0.director)为   generateAlias0左连接,将generateAlias0.machines作为机器加入     左加入generateAlias0.emails作为电子邮件,其中   generateAlias0.id =:param0

     

]

看起来,电子邮件就像是一个字符串,而不是字符串的集合...

0 个答案:

没有答案