registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web applicat

使用Hibernate建立多对一关系时出现了这样的错误,记录一下解决的过程。
出现这个问题的原因有很多种,我这里的原因主要有两点:

1、手动创建了数据库中的表,而不是通过hibernate来创建,删除手动创建的表,然后运行程序,让hibernate创建,因为我选择的建表策略是update。

2、然后出现了如下错误:
Unable to execute schema management to JDBC target [create table dict_id varchar(255) not null auto_increment···········]
Incorrect column specifier for column ‘dict_id’
建表失败

这里是因为主键生成策略我选择的是native,但是,主键是varchar类型,varchar类型不能设置auto_increment自动增长。

解决办法有两种:
(1) 将主键设为int类型(在代码中设置)
(2) 或者将主键生成策略改为:assigned

猜你喜欢

转载自blog.csdn.net/fighting_sxw/article/details/80784012