美文网首页
springboot2.0+jpa整合遇到的坑

springboot2.0+jpa整合遇到的坑

作者: 轩辕花狐貂 | 来源:发表于2018-06-02 19:06 被阅读0次

错误信息:Table ‘sell.hibernate_sequence‘ doesn‘t exist

错误原因:实体主键没有配置主键自增长

错误写法:

package com.itcast.entity;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import org.hibernate.annotations.DynamicUpdate;

import lombok.Data;

/**

* 商品类目实体

* @author jack

*

*/

@Entity

@DynamicUpdate

@Data

public class ProductCategory {

/**类目id*/

@Id

@GeneratedValue

private Integer categoryId;

/**类目名称*/

private String categoryName;

/**类目编号*/

private Integer categoryType;

public ProductCategory(){}

public ProductCategory(String categoryName, Integer categoryType) {

this.categoryName=categoryName;

this.categoryType=categoryType;

}

/*

public Integer getCategoryId() {

return categoryId;

}

public void setCategoryId(Integer categoryId) {

this.categoryId = categoryId;

}

public String getCategoryName() {

return categoryName;

}

public void setCategoryName(String categoryName) {

this.categoryName = categoryName;

}

public String getCategoryType() {

return categoryType;

}

public void setCategoryType(String categoryType) {

this.categoryType = categoryType;

}

@Override

public String toString() {

return "ProductCategory [categoryId=" + categoryId + ", categoryName=" + categoryName + ", categoryType="

+ categoryType + "]";

}

*/

}

正确写法

package com.itcast.entity;

import javax.persistence.Entity;

import javax.persistence.GeneratedValue;

import javax.persistence.GenerationType;

import javax.persistence.Id;

import org.hibernate.annotations.DynamicUpdate;

import lombok.Data;

/**

* 商品类目实体

* @author jack

*

*/

@Entity

@DynamicUpdate

@Data

public class ProductCategory {

/**类目id*/

@Id

@GeneratedValue(strategy = GenerationType.IDENTITY)

private Integer categoryId;

/**类目名称*/

private String categoryName;

/**类目编号*/

private Integer categoryType;

public ProductCategory(){}

public ProductCategory(String categoryName, Integer categoryType) {

this.categoryName=categoryName;

this.categoryType=categoryType;

}

/*

public Integer getCategoryId() {

return categoryId;

}

public void setCategoryId(Integer categoryId) {

this.categoryId = categoryId;

}

public String getCategoryName() {

return categoryName;

}

public void setCategoryName(String categoryName) {

this.categoryName = categoryName;

}

public String getCategoryType() {

return categoryType;

}

public void setCategoryType(String categoryType) {

this.categoryType = categoryType;

}

@Override

public String toString() {

return "ProductCategory [categoryId=" + categoryId + ", categoryName=" + categoryName + ", categoryType="

+ categoryType + "]";

}

*/

}

相关文章

网友评论

      本文标题:springboot2.0+jpa整合遇到的坑

      本文链接:https://www.haomeiwen.com/subject/uacksftx.html