When working on a project in which we use hibernate, I get
as exception.
The spring exception was:
The only field I have in my entity named 'date' is not marked with column annotation. So it should not be mapped to database table and thus should not be used in the query right?
No, think again. Every field in the entity class is mapped and column annotation is optional. So if you ever want hibernate to ignore a field in your entity (because either this field is not present in the table or you don't want to use it somehow), use transient annotation.
So,
must become this
1 | Unknown column 'date' in 'field list' |
1 | org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [ select this_.ID as ID3010_0_, this_. date as date3010_0_, |
1 | @Entity |
2 | public class MyEntity implements Serializable |
3 | { |
4 | private String date; |
5 |
6 | @Id |
7 | @GeneratedValue |
8 | @Column (name = "ID" ) |
9 | private Long id; |
01 | @Entity |
02 | public class MyEntity implements Serializable |
03 | { |
04 | @Transient |
05 | private String date; |
06 |
07 | @Id |
08 | @GeneratedValue |
09 | @Column (name = "ID" ) |
10 | private Long id; |