我使用 JPA 进行 mysql 操作,但有几次在通过 JPA 执行 mysql 保存操作时遇到错误。执行保存操作时出错=>
无法打开 JPA EntityManager 进行事务;密钥“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
}
Run Code Online (Sandbox Code Playgroud)
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`)
)
Run Code Online (Sandbox Code Playgroud)
存储库类:
@Repository
public …Run Code Online (Sandbox Code Playgroud)