I am trying to insert a record into a database (MySQL) using Entity Class and Entity Manager. But one of the fields is the automatically incrementing primary key, so if I did not provide the value manually, the insert would not be successful.
public boolean newContributor(String name, String email, String country, Integer contactable, String address) { Contributors contributor = new Contributors();
How to solve such a problem? Is there a way to tell the entity manager to try pasting without an ID field and using a NULL
value instead.
Update: Here is the part of the entity class defining id
... @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @NotNull @Column(name = "id") private Integer id; @Basic(optional = false) @NotNull @Size(min = 1, max = 50) ....
source share