Java Hibernate:字段列表中的未知列

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22976563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 19:42:39  来源:igfitidea点击:

Hibernate: Unknown column in field list

javahibernate

提问by

I am getting the following error from my Hibernate code:

我从我的 Hibernate 代码中收到以下错误:

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

There is no such bulletin_datecolumn 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.

bulletin_date我的表中没有这样的列,我的模型类中也没有这样的名称。它只是被称为date。这是我收到错误的行。

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

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

这是我的模型类(我省略了 getter 和 setter):

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    |                |
+----------+---------------+------+-----+---------+----------------+

采纳答案by

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

我的文件中有错误的列名Bulletin.hbm.xml。当我纠正它时,问题就解决了。