zoukankan      html  css  js  c++  java
  • 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,为什么这边没有支持而报错?

  • 相关阅读:
    弹窗
    [转]JNI字段描述符“([Ljava/lang/String;)V”
    [转]JNIEnv解析
    [转]"error while loading shared libraries: xxx.so.x" 错误的原因和解决办法
    [转]Linux下如何查看版本信息
    [转]apt-get 与 yum的区别 (转)
    我的tesseract学习记录(二)
    [转]pkg-config的用法
    [转]linux 创建连接命令 ln -s 软链接
    如何写makefile
  • 原文地址:https://www.cnblogs.com/kongieg/p/11381411.html
Copyright © 2011-2022 走看看