• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

How to I map DATETIME to Spring Boot?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So far I used MySQL's DATE data type, which I mapped like:

I hoped that changing temporal's value from DATE to TIME would work. Unfortunately, it throws an exception. What can be done now? Is there an alternative?

P.S. Why I must keep part: new Date();? Shouldn't it be mapped to the current Date if I omit that field from Postman? If I omit it, I get null.
 
Bartender
Posts: 560
10
IntelliJ IDE Spring Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would it be set to current date?
 
Stefan Jankovic
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then what does @Temporal even do? Just formats Date object?
 
Sheriff
Posts: 22504
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Temporal tells JPA how to map generic date/time types like java.util.Date and I believe also java.util.Calendar to date, time or datetime columns. Other types like java.sql.Date, java.sql.Time, java.sql.Timestamp and classes from java.time already contain information to auto-guess the database type, but java.util.Date is so generic that it can be mapped to any of the three.

Stefan, you said you changed the value in @Temporal. Did you also change the actual database column type? Because the two must match. And if you want the date and time, you should use TIMESTAMP, not TIME. DATE is only the date part, TIME is only the time part, TIMESTAMP is both combined.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic