问题描述
首先<hibernate-mapping>
中的各属性name填写无误
在hibernate.cfg.xml
设置<property name="hibernate.hbm2ddl.auto">update</property>
使hibernate自动创建table,
控制台只输出CURD操作的SQL(如下),没有创建表的SQL语句
Hibernate:
insert
into
user
(username, password)
values
(?, ?)
并且报错org.hibernate.exception.SQLGrammarException: could not execute statement
解决方案
注释或删除hibernate.cfg.xml
中的方言设置
<!--<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>-->
结果
控制台输出
Hibernate:
create table user (
id integer not null auto_increment,
username varchar(255),
password varchar(255),
primary key (id)
) engine=InnoDB
Hibernate:
insert
into
user
(username, password)
values
(?, ?)
并且在数据库中自动建好了table