1

Can't get time field from input, constantly getting error message:

Field error in object 'recipe' on field 'prepTime': rejected value [04:00]; codes [typeMismatch.recipe.prepTime,typeMismatch.prepTime,typeMismatch.java.sql.Time,typeMismatch];

arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [recipe.prepTime,prepTime]; arguments []; default message [prepTime]]; default message [Failed to convert property value of type [java.lang.String] to required type [java.sql.Time] for property 'prepTime'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@org.springframework.format.annotation.DateTimeFormat java.sql.Time] for value '04:00'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.Date] to type [@org.springframework.format.annotation.DateTimeFormat java.sql.Time]]

My POJO class:

@Entity
public class Recipe {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Lob
    private byte[] photo;

    @Size (min=3, max=100, message = "size of field Name must be between 3 and 100")
    private String name;

    private String description;

    @ManyToOne
    private Category category;

    @DateTimeFormat(pattern = "mm:ss")
    private Time prepTime;

    @DateTimeFormat(pattern = "mm:ss")
    private Time cookTime;

    private String addedFlag;

and input field in form html:

<input type="time" th:placeholder="${recipe.prepTime}" th:field="${recipe.prepTime}"/>

So, what I'm doing wrong?

6
  • Try to add @Temporal annotation. Commented Aug 28, 2016 at 11:23
  • Can't add that annotation to Time field Commented Aug 28, 2016 at 11:25
  • 1
    Annotation @Temporal can be added to DateTime or Date fields only, not Time Commented Aug 28, 2016 at 11:30
  • 1
    try this : stackoverflow.com/questions/9533935/… Commented Aug 28, 2016 at 11:30
  • 1
    Try using hibernate converter. See stackoverflow.com/questions/27750026/… Commented Aug 28, 2016 at 11:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.