SQLStateConverter.handledNonSpecificException hibernate

I have the following object in Hibernate:

@Entity public class Contact implements Serializable { private static final long serialVersionUID = 1L; @Temporal(TemporalType.DATE) private Date birthday; } 

When I call this sleep mode method:

 public Object get(Class entityClass, Serializable id) throws HibernateException { return get( entityClass.getName(), id ); } 

I get the following exception:

 org.hibernate.exception.GenericJDBCException: could not load an entity: [com.mycompany.model.Contact#3] at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) } 

I tried this simple code:

 Statement st = conn.createStatement(); ResultSet res = st.executeQuery("select registration_date from contact where contact_id=3"); Date i = res.getDate(1); 

And it works great.

What is the problem?

The Date type is java.util.Date in both cases.

EDITED

I debugged it more and saw that exception:

 Bad format for DATE '517' in column 2. 

Date: 1985-05-17

+4
source share
2 answers

Very stupid problem.

The field name in Hibernate was birthday , and in db I was registration_date .

birthday in db was an int field.

+4
source

you can use the notation included in the Hibernate JPA implementation

 @Column(name="registration_date") private Date birthday; 

This way you do not need to change the name of the DB column.

Greetings

+1
source

Source: https://habr.com/ru/post/1394421/


All Articles