注意:測試數據庫為Mysql
編寫Hibernate配置文件,然后通過SchemaExport類創建表,以前都能成功實現,但是今天卻遇到了問題。
編寫了三個“.hbm.xml”文件,然后通過SchemaExport類創建表,控制台輸出如下Sql語句:
drop table if exists t_admin
drop table if exists t_message
drop table if exists t_websiteinfo
create table t_admin (userName varchar(20) not null, password varchar(20), primary key (userName))
create table t_message (id integer not null auto_increment, userName varchar(20), email varchar(20), websize varchar(100), qq varchar(10), content longtext, facePic varchar(30), headPic varchar(30), postDate varchar(20), replayContent longtext, replayDate varchar(20), show bit, userIP varchar(15), top bit, primary key (id))
create table t_websiteinfo (id integer not null auto_increment, name varchar(20), needEmail bit, supportHtml bit, needCheckup bit, contentLength integer, pageSize integer, replayTip varchar(30), replayColor varchar(20), badWords longtext, primary key (id))
進入數據庫,卻發現只有t_admin和t_websiteinfo兩張表,t_message表不存在,試了N次都不行,重新啟動MyEclipse和Mysql,還是不行,百度、谷歌無果。休息會突然想到是不是某個屬性是數據庫的關鍵字,於是把屬性復
制到SQLyog Enterprise中,發現show變成藍色了,修改成showed,在Export,成功了。果真是關鍵字惹的禍,
下次要注意了。
PS:寫了個類,boolean型,命名為isShow,Java中生成get方法如下:
public boolean isShow()
{
return isShow;
}
使用Hibernate時會報找不到isShow屬性的get方法異常。所以給變量起名字也要注意了。