Caused by: java.sql.SQLSyntaxErrorException: Table 'sell.hibernate_sequence' doesn't exist
数据表:
create table 'product_category'( 'category_id' int not null auto_increment, 'category_name' varchar(64) not null comment '类目名字', ......
domain:
@Entity public class ProductCategory { @Id @GeneratedValue private Integer categoryId; private String categoryName; private Integer categoryType; setter... getter...
Repository:
public interface ProductCategoryRepository extends JpaRepository<ProductCategory,Integer> { }
测试代码:
@Test public void saveTest(){ ProductCategory productCategory = new ProductCategory(); productCategory.setCategoryName("测试b"); productCategory.setCategoryType(3); repository.save(productCategory); }
报错:Caused by: java.sql.SQLSyntaxErrorException: Table 'sell.hibernate_sequence' doesn't exist
解决:在domain实体类指明主键生成策略,保持数据库一致
@Entity public class ProductCategory { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer categoryId; private String categoryName; private Integer categoryType;
JPA四种生成策略了解下。
疑点:原文使用@GeneratedValue注解,即@GeneratedValue(strategy = GenerationType.AUTO),不是应该根据数据库支持的主键生成策略自动选择合适的吗,数据库中使用了auto_increment,为什么这边没有支持而报错?
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)