Thymeleaf Failed to convert from type [java.lang.String] to type [java.lang.Long] for value
Делаю приложение на Spring Boot с использованием Thymeleaf.
Есть сущность, которая в качестве поля содержит другую сущность. При попытке в форме Thymeleaf'а внедрить один объект в это поле другого получаю ошибку:
Failed to convert property value of type java.lang.String to required type ru.terentyev.EffectiveMobile.entities.Person for property executor; Failed to convert from type [java.lang.String] to type [java.lang.Long] for value [ru.terentyev.EffectiveMobile.entities.Person@41544fe9]
А именно не получается полю executor объекта task присвоить в качестве значения объект сущности Person.
Вот форма:
<form th:method="PATCH" th:action="@{/tasks/edit}" th:object="${task}">
<input type="hidden" th:field="*{id}" th:value="${task.id}"/>
<p> Название: <input type="text" th:field="*{title}"/></p>
<p> Описание: <input type="text" th:field="*{description}"/></p>
<p> Статус: <select th:field="*{status}">
<option th:each="statusT : ${T(ru.terentyev.EffectiveMobile.entities.Task.Status).values()}"
th:value="${statusT}" th:text="${statusT?.translation}"></option>
</select><br></p>
<p> Приоритет: <select th:field="*{priority}">
<option th:each="priorityT : ${T(ru.terentyev.EffectiveMobile.entities.Task.Priority).values()}"
th:value="${priorityT}" th:text="${priorityT?.translation}"></option>
</select><br></p>
<p> Исполнитель: <select th:field="*{executor}">
<option th:each="executorName : ${executors}"
th:value="${executorName}" th:text="${executorName.name}"></option>
</select><br></p>
<div th:if="${#fields.hasAnyErrors()}">
<span th:each="fieldError : ${#fields.allErrors()}">
<p th:text="${fieldError}"/>
</span>
</div>
<input type="hidden" th:field="${task.author}"/>
<input type="hidden" th:field="${task.createdAt}"/>
<input type="hidden" th:field="${task.editedAt}"/>
<input type="submit" value="Сохранить"/>
<br><br><br>
</form>
Вот сущности:
@Entity
@Table(name = "tasks")
public class Task {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank(message = "Заголовок не может быть пустым")
private String title;
@NotBlank(message = "Описание не может быть пустым")
private String description;
@NotNull(message = "У задачи должен быть статус")
@Enumerated(EnumType.STRING)
private Status status;
@NotNull(message = "У задачи должен быть приоритет")
@Enumerated(EnumType.STRING)
private Priority priority;
@ManyToOne
@JoinColumn(name = "author_id", referencedColumnName = "id")
private Person author;
@NotNull(message = "У задачи должен быть исполнитель")
@ManyToOne
@JoinColumn(name = "executor_id", referencedColumnName = "id")
private Person executor;
@OneToMany(mappedBy = "task")
private List<Comment> comments;
@CreatedDate
private LocalDateTime createdAt;
private LocalDateTime editedAt;
public Task(){}
// getters, settes
@Entity
@Table(name = "people")
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotBlank
private String name;
@Email
private String email;
@Size(min = 5, message = "Пароль должен содержать минимум 5 символов")
private String password;
private transient String passwordConfirm;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "author")
private List<Task> createdTasks;
@OneToMany(fetch = FetchType.EAGER, mappedBy = "executor")
private List<Task> executableTasks;
@CreatedDate
private LocalDateTime registrationDate;
public Person(){}
// getters, setters