ProductCategory save测试方法报错

来源:4-1 买家类目-dao(上)

JasonXiang

2018-04-12

查看了Stackoverflow,一定要在data object- productCategory添加以下注释才能跑通

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer categoryId;

不加(strategy = GenerationType.IDENTITY)会报以下的错误:

Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'sell.hibernate_sequence' doesn't exist
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
 at com.mysql.jdbc.Util.getInstance(Util.java:408)
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:944)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3976)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3912)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2530)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2683)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2486)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1858)
 at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1966)
 at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52)
 at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java)
 at org.hibernate.id.enhanced.TableStructure.executeQuery(TableStructure.java:216)
 at org.hibernate.id.enhanced.TableStructure.access$300(TableStructure.java:46)
 at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:138)
 at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:126)
 at org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:55)
 at org.hibernate.jdbc.AbstractReturningWork.accept(AbstractReturningWork.java:34)
 at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:57)
 ... 74 more

写回答

1回答

Code_M0keny

2018-04-12

数据库里product_category表中的id字段你设置了自增长了么。

0
1
JasonXiang
查过MySQL workbench, category_id column已经勾上Auto Increment属性。可能是spring Boot 2.0版本的问题
2018-04-12
共1条回复

Spring Boot双版本(1.5/2.1) 打造企业级微信点餐系统

从0到1开发中小型企业级Java应用,并学会迭代重构技巧

6410 学习 · 5247 问题

查看课程