I'm using the EclipseLink implementation of JPA and I've got a problem.
Here is my entity class:
@Entity
@Table(name = "attendances")
public class Attendance implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Short id;
....
In my MySQL table (that is the underlying data store) I have auto_increment flag also set.
How can I get the auto-generated value (id field) before persisting the entity? So if there are 3 entities in the table (id IN (1, 2, 3)), I want to get 4 as the next auto-generated value.
The only workaround I have is:
- Get the id of the entity with the largest
idfield.
Is that all I can do?