Reputation: 1891
I am trying to persist only the time in HH:mm:ss format and the startDay only as a day of the week like 'Monday', 'Tuesday' etc
using Java8, Spring Data JPA and MySQL
| startTime |startDay
08:00:00 Monday
Upvotes: 0
Views: 463
Reputation: 36
To define an Entity covering your requirements you could use java.sql.Time for the startTime which is mapped to MySQL TIME and the java.time.DayOfWeek enumeration for startDay .
@javax.persistence.Entity
public class Event {
private java.sql.Time startTime;
private java.time.DayOfWeek startDay;
...
}
For more details in JPA related date and time mappings have a look at http://thorben-janssen.com/hibernate-jpa-date-and-time/ . For JPA enumeration mappings check https://thorben-janssen.com/hibernate-enum-mappings/ .
Note that in case you are using Hibernate 5 you could also use java.time.LocalTime instead of java.sql.Time for the startTime.
Upvotes: 1