0

I have some probles with JPA @Temporal(TemporalType.DATE) annotation, during application demployment. So I created spring data + postgres 9.5 + hibernate 4.3.10 app and setted hbm2ddl.auto to 'validate'.

hibernate.hbm2ddl.auto = validate

Here is Entity:

@Entity
@Table(name = "locomotive")
public class LocomotiveEntity {

    private Long locomotiveId;
    @Column(name = "status")
    private int status;
    @Temporal(TemporalType.DATE)
    private java.util.Date constructionYear;
...

Also I created locomotive table using this script:

CREATE TABLE "locomotive"
(
    "locomotiveId"  bigserial PRIMARY KEY,
    "status" integer NOT NULL,
    "constructionYear" DATE NOT NULL
);

But I see exception during demployment:

Caused by: org.hibernate.HibernateException: Wrong 
column type in public.constructionYear for column constructionYear.
 Found: date, expected: timestamp

So I have 'DATE' type column in my db, and 'DATE' java type. What I did wrong?

1
  • If you look at the PostgreSQL documentation, you see that the date type does not include the time of day. You have to use at least timestamp. Commented Feb 29, 2016 at 10:20

1 Answer 1

0

Try to use TemporalType.TIMESTAMP like this:

 @Temporal(TemporalType.TIMESTAMP)
 private Date constructionYear;
Sign up to request clarification or add additional context in comments.

Comments

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.