1

I'm having a problem with inserting Time correctly into the PostgreSQL database. Making web app with SpringBoot, using JPARepository and hibernate. Using this dialect:

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL95Dialect

I have a class:

@Entity
public class Class {
//other stuff
@Column(name = "date_and_time")
private LocalDateTime dateAndTime;

I need some test data and when I start my app with this script:

insert into class(date_and_time) values (DATE('2020-06-10 18:43:20');

the result in my database looks like this 2020-06-10 00:00:00

Is there any way I can insert time properly in my database?

1
  • Have you tried marking it as @Temporal(TIMESTAMP) ? Commented Jun 19, 2020 at 0:15

1 Answer 1

1

You are casting your datetime to only date when you use the ‘DATE’ function, so you lose the time information. Simply remove the function and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that solved my problem. I found out just now that ('2020-06-10 18:43:20')::timestamp also gets the job done.

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.