休眠:字段列表中的未知列 [英] Hibernate: Unknown column in field list
本文介绍了休眠:字段列表中的未知列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException:未知列'bulletin0_.bulletin_date'in'field list'
没有这样的 bulletin_date
列在我的表中,我的模型类中也没有这样的名称。它只是被称为日期
。
查询查询= session.createQuery(来自公告where where approved = true这里是我得到错误的那一行。 );
这是我的模型类(我将getters和setters排除在外):
public class Bulletin {
@Id
@Column(name =id)
@GeneratedValue
private int id;
@Column(name =date)
private String date;
@Column(name =name)
私有字符串名称;
@Column(name =subject)
private String subject;
@Column(name =note)
private String note;
@Column(name =approved)
private boolean approved;
}
这是我的表格定义。
+ ---------- + --------------- + ------ + - ---- + --------- + ---------------- +
|字段|类型|空| Key |默认|额外|
+ ---------- + --------------- + ------ + ----- + ----- ---- + ---------------- +
| id | int(11)| NO | PRI | NULL | auto_increment |
|日期| varchar(10)|是| | NULL | |
|名称| varchar(30)|是| | NULL | |
|主题| varchar(50)|是| | NULL | |
|注意| varchar(2500)|是| | NULL | |
|批准| tinyint(1)|是| | NULL | |
+ ---------- + --------------- + ------ + ----- + ----- ---- + ---------------- +
解决方案
我的 Bulletin.hbm.xml
文件中列名错误。当我纠正它时,问题就解决了。
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 | |
+----------+---------------+------+-----+---------+----------------+
解决方案
I had the wrong column names in my Bulletin.hbm.xml
file. When I corrected it, the problem was solved.
这篇关于休眠:字段列表中的未知列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文