I am using JPA for mysql operations, but the few times I am getting error while performing mysql save operations through JPA. Error while performing save operation =>
Could not open JPA EntityManager for transaction; Duplicate entry for key 'PRIMARY'
Table Model Class:
@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 Schema:
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 Class:
@Repository
public interface TableXRepository extends CrudRepository<tableX,Long> {
}
Mysql Operation Class:
@Component
@Transactional
public class tableXoperationImpl implements ItableXoperation {
@Autowired
private TableXRepository tableXRepository;
public void save(tableX data) {
tableXRepository.save(data);
}
}
is anything, I am missing here, any help will be appreciated.