spring測試save方法報錯
阿新 • • 發佈:2018-08-25
leg clas creat ould seq save eth val ble
用test類測試service的save方法時,報錯如下:
2018-08-24 21:52:13,506 - could not read a hi value 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)
後經過調查,原因是實體類的自增主鍵寫的有問題,
原寫法:
@GeneratedValue private Integer categoryId;
現寫法:
@GeneratedValue(strategy = GenerationType.IDENTITY) //設置主鍵生成模式為自增 private Integer categoryId;
加上策略後,問題解決
spring測試save方法報錯