'java.lang.String' для требуемого типа 'java.util.Set' для свойства 'stores'; - PullRequest
0 голосов
/ 09 ноября 2019

enter image description here

Я могу добавить магазин, но когда я хочу добавить товар в магазин, я не могу добавить и показать ошибку.

база данных enter image description here enter image description here enter image description here

Текст ошибки

[Ошибка поля в объекте «продукт» в поле «магазины»: отклоненазначение [7270620c-d635-449c-a9a8-c4f4f2a3802c];коды [typeMismatch.product.stores, typeMismatch.stores, typeMismatch.java.util.Set, typeMismatch];Аргументы [org.springframework.context.support .DefaultMessageSourceResolvable: codes [product.stores, stores];аргументы [];сообщение по умолчанию [магазины]];сообщение по умолчанию [Не удалось преобразовать значение свойства типа 'java.lang.String' в требуемый тип 'java.util.Set' для свойства 'stores';вложенным исключением является org.springframework.core.convert.ConversionFailedException: не удалось преобразовать тип [java.lang.String] в тип [java.lang.Integer] для значения '7270620c-d635-449c-a9a8-c4f4f2a3802c';вложенное исключение - java.lang.NumberFormatException: для входной строки: "7270620c-d635-449c-a9a8-c4f4f2a3802c"]]

Product

package com.gpch.hotel.model;


import com.fasterxml.jackson.annotation.JsonBackReference;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Set;

@Getter
@Setter
@Entity
@Table(name = "product")
public class Product {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "product_id")
    private String id;
    @Column(name = "productname")
    private String productname;
    @Column(name = "price")
    private int price;

    @JsonIgnore
    @ManyToMany(fetch = FetchType.LAZY)
    @JoinTable(name = "product_store", joinColumns = @JoinColumn(name = "product_id"), inverseJoinColumns = @JoinColumn(name = "store_id"))
    private Set<Store> stores;

    public String getNameStore() {

        return stores.iterator().next().getStoreName();
    }

    public String getIdStore() {
        return stores.iterator().next().getId();
    }

}

Магазин

package com.gpch.hotel.model;


import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;

@Getter
@Setter
@Entity
@Table(name = "store")
public class Store {
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "store_id")
    private String id;
    @Column(name = "storename")
    @NotEmpty(message = "*Please provide a store name")
    private String storeName;
    @Column(name = "status")
    private String status;

    @ManyToMany(mappedBy = "stores", cascade = CascadeType.REMOVE)
    private List<Product> products;

    public String Listnameproducts() {
        ArrayList<String> Productnames = new ArrayList<String>();
        for (Product temp : products) {
            Productnames.add(temp.getProductname());
        }
        return Productnames.toString();
    }
}

форма

 <form autocomplete="off" action="#" th:action="@{/products/add_product}"
                      th:object="${product}" method="post" class="form-horizontal"
                      role="form">
                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="addproductname" th:text="#{product.table.name.text}"></label>
                            <input type="text" class="form-control" id="addproductname" th:field="*{productname}"
                                   required="required"/>
                        </div>
                        <div class="form-group col-md-6">
                            <label for="addprice" th:text="#{product.table.price.text}"></label>
                            <input type="number" class="form-control" id="addprice" th:field="*{price}"
                                   required="required"/>
                        </div>
                    </div>

                    <div class="form-row">
                        <div class="form-group col-md-6">
                            <label for="addstores" th:text="#{product.table.store.text}"></label>
                            <select id="addstores" class="form-control" th:field="*{stores}">
                                <option th:each="store : ${liststores}" th:value="${store.id}"
                                        th:text="${store.storeName}"></option>
                            </select>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary btn-icon-split" type="button" data-dismiss="modal">
                              <span class="icon text-white-50">
                      <i class="fas fa-times"></i>
                                   </span> <span class="text" th:text="#{product.ma.cancel.text}"></span>
                        </button>
                        <button class="btn btn-success btn-icon-split" type="submit">
                             <span class="icon text-white-50">
                      <i class="fas fa-save"></i>
                                   </span> <span class="text" th:text="#{product.ma.save.text}"></span>
                        </button>
                    </div>
                </form>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...