I am using MySQL database.
My table is an employee in which there are two primary keys, out of which one is auto incremented.
My code is:
@Embeddable
public class EmployeeId implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@Column(name = "id", nullable = false)// this i want to increment
private int id;
// I have tried and @GeneratedValue(strategy = GenerationType.IDENTITY),
//@GeneratedValue(strategy = GenerationType.IDENTITY)
//and @GeneratedValue(strategy = GenerationType.TABLE)
//@GeneratedValue(strategy = GenerationType.AUTO, generator = "id") @SequenceGenerator(name = "id", sequenceName = "id")
@Column(name = "gender_key", nullable = false)
private id gender_key;
}
@Entity
@Table(name = "employee")
public class employee {
@EmbeddedId
private EmployeeId employeeId;
private String emp_name;
private String mobile_no;
employee() {
}}
public interface employeeRepository extends
JpaRepository<employee, EmployeeId> {
}
In My Controller I want id after employeeRepository.save(bean); method because i want to save that id in different table .
logger.info("id is --- > "+id);
But I am getting always 0 value of id.
How can I get the incremented value of id which is inserted into MySQL table?
Please Help.
Thanks in advance.