gpt4 book ai didi

mysql - JPA/Spring-boot key 'PRIMARY' 的重复条目

转载 作者:行者123 更新时间:2023-12-02 04:27:20 26 4
gpt4 key购买 nike

我正在使用 JPA 进行 mysql 操作,但有几次我在通过 JPA 执行 mysql 保存操作时出错。
执行保存操作时出错 =>

Could not open JPA EntityManager for transaction; Duplicate entry for key 'PRIMARY'



表模型类:
@Entity
@Table(name="table_x")
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
@TypeDefs({
@TypeDef(name = "json", typeClass = JsonStringType.class),
@TypeDef(name = "jsonb", typeClass = JsonBinaryType.class),
})
public class tableX implements Serializable {

@Id
@Column(name="product_id")
private Long productId;

@Column(name="parent_id")
private Long parentId;

// other fields
}

Mysql 架构:
 CREATE TABLE `table_x` (
`product_id` int(12) unsigned NOT NULL,
`parent_id` int(12) unsigned DEFAULT NULL,
// other fields
PRIMARY KEY (`product_id`)
)

存储库类:
@Repository
public interface TableXRepository extends CrudRepository<tableX,Long> {
}

Mysql 操作类:
@Component
@Transactional
public class tableXoperationImpl implements ItableXoperation {

@Autowired
private TableXRepository tableXRepository;

public void save(tableX data) {
tableXRepository.save(data);
}
}

是什么,我在这里失踪,任何帮助将不胜感激。

最佳答案

请使用 @GeneratedValue(strategy = GenerationType.AUTO)productId .

关于mysql - JPA/Spring-boot key 'PRIMARY' 的重复条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53079210/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com