Hibernate在Database First开发中找不到表

时间:2016-07-26 13:10:53

标签: hibernate grails gorm

我的Grails应用程序遇到了另一个问题。我创建并填充了我的Site_Menu表,如下所示。当我尝试访问控制器功能时,出现无法找到表的错误。我将在下面提供我的代码。

CREATE TABLE `Site_Menu` (
  `ID` bigint(20) NOT NULL AUTO_INCREMENT,
  `MenuDisplay` varchar(100) NOT NULL,
  `MenuLink` varchar(256) NOT NULL,
  `MenuTarget` varchar(25) DEFAULT NULL,
  `MenuSortOrder` int(11) NOT NULL,
  PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;

INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Home Page', 'index.html', null, 1);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('About the BPO Elks', 'aboutelks.html', null, 2);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Drug Awareness Program', 'dap.html', null, 3);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Elks National Fund', 'enf.html', null, 4);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('G.U.M.B.O. Games', 'majorproject.html', null, 5);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Louisiana Elks Fund', 'lef.html', null, 6);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Scholarships', 'scholarships.html', null, 7);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Veterans Services', 'vavs.html', null, 8);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('About Us', 'aboutus.html', null, 9);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Our Facilities', 'facilities.html', null, 10);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Lodge Officers & Committee Chairs', 'officers.html', null, 11);
INSERT INTO Site_Menu (MenuDisplay, MenuLink, MenuTarget, MenuSortOrder)
VALUES ('Contact Us', 'contactus.html', null, 12);

COMMIT;

我的域名模型如下:

package plaquemineelks

class SiteMenu {

    Long id

    String title
    String link
    String target
    Integer sortOrder

    static constraints = {
        title (blank: false)
        link (blank: false)
        sortOrder (blank: false)
    }

    static mapping = {
        table: "Site_Menu"
        id column: "ID"
        title column: "MenuDisplay"
        link column: "MenuLink"
        target column: "MenuTarget"
        sortOrder column: "MenuSortOrder"
        version false
    }
}

控制器看起来像:

package plaquemineelks

class SiteMenuController {

    def index() { }

    def getMenu() {
        var results = SiteMenu.findAll()

        render(contentType: 'text/json') {[
            'results': results,
            'status': results ? "OK" : "Nothing present"
        ]}
    }
}

我得到的错误是:

URI     / PlaquemineElks / SiteMenu /使用getMenu 类     com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException 信息     表' PlaquemineElks.site_menu'不存在

我已经尝试重命名表和类,我重新创建了一切。我的日历类和控制器工作正常,为什么这个给我带来问题?

感谢您对此问题的帮助以及我的上一次。

1 个答案:

答案 0 :(得分:0)

基于official docs而不是:

static mapping = {
    table: "Site_Menu"
    ...
}

使用:

static mapping = {
    table name: "Site_Menu"
    ...
}

static mapping = {
    table "Site_Menu"
    ...
}