Frank Frank - 3 months ago 30
Java Question

Hibernate: Unknown column in field list

I am getting the following error from my Hibernate code:

com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: Unknown column 'bulletin0_.bulletin_date' in 'field list'


There is no such
bulletin_date
column in my table, nor is there such a name in my model class. It's just called
date
. Here is the line where I'm getting the error.

Query query = session.createQuery("from Bulletin where approved = true");


Here is my model class (I'm leaving out the getters and setters):

public class Bulletin {
@Id
@Column(name="id")
@GeneratedValue
private int id;

@Column(name="date")
private String date;

@Column(name="name")
private String name;

@Column(name="subject")
private String subject;

@Column(name="note")
private String note;

@Column(name="approved")
private boolean approved;
}


Here is my table definition.

+----------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| date | varchar(10) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
| subject | varchar(50) | YES | | NULL | |
| note | varchar(2500) | YES | | NULL | |
| approved | tinyint(1) | YES | | NULL | |
+----------+---------------+------+-----+---------+----------------+

Answer

I had the wrong column names in my Bulletin.hbm.xml file. When I corrected it, the problem was solved.

Comments