tengo un archivo data.sql
INSERT INTO tbl_categories (id, name) VALUES (1, 'shoes');
INSERT INTO tbl_categories (id, name) VALUES (2, 'books');
INSERT INTO tbl_categories (id, name) VALUES (3, 'electronics');
INSERT INTO tbl_products (id, name, description, stock,price,status, create_at,category_id)
VALUES (1, 'adidas Cloudfoam Ultimate','Walk in the air in the black / black CLOUDFOAM ULTIMATE running shoe from ADIDAS',5,178.89,'CREATED','2018-09-05',1);
INSERT INTO tbl_products (id, name, description, stock,price,status, create_at,category_id)
VALUES (2, 'under armour Men ''s Micro G Assert – 7','under armour Men ''Lightweight mesh upper delivers complete breathability . Durable leather overlays for stability ',4,12.5,'CREATED','2018-09-05',1);
INSERT INTO tbl_products (id, name, description, stock,price,status, create_at,category_id)
VALUES (3, 'Spring Boot in Action','under armour Men '' Craig Walls is a software developer at Pivotal and is the author of Spring in Action',12,40.06,'CREATED','2018-09-05',2);
mis entidades son:
@Entity
@Table(name = "tbl_categories")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Category {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String name;
}
@Entity
@Table(name = "tbl_products")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String name;
private String description;
private Double stock;
private Double price;
private String status;
@Column(name = "create_at")
@Temporal(TemporalType.TIMESTAMP)
private Date createAt;
@ManyToOne
@JoinColumn(name = "category_id")
private Category category;
}
el problema es que al ingresar un nuevo producto, me salta el error de repeticion de llave primaria.
me di cuenta que a los 3 primeros intentos sale ese error, entra en conflicto con el id del registro 1, luego con el 2, luego con el 3, pero al cuarto ya me deja registrar. creo que el problema es que identiti esta empezando desde el 1, y en cada intento va subiendo hasta llegar al 4. como puedo hacer para resolver este error. dejo el archivo de configuracion:
#Application Configuration
server:
port: 8091
# To See H2 Console in Browser:
# http://localhost:8091/h2-console
# Enabling H2 Console
spring:
h2:
console:
enabled: true
# ===============================
# DB
# ===============================
datasource:
url: jdbc:h2:mem:productDB;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
driverClassName: org.h2.Driver
username: sa
password:
# ===============================
# JPA / HIBERNATE
# ===============================
jpa:
show-sql: true
hibernate:
ddl-auto: create-drop
database-platform: org.hibernate.dialect.H2Dialect
properties:
hibernate:
show_sql: true
use_sql_comments: false
format_sql: false
defer-datasource-initialization: true
talves sea algo con la configuracion de h2 o nose. pueden ayudarme.