Specify the sequence:
package com.liguoliang.jee.vo; /** * Represents Client. * @author Guoliang * */ @Entity @Table (name="Client") public class Client { @Id @Column(name="id") @SequenceGenerator(name="my_seq", sequenceName="CLIENT_ID_SEQUENCE") @GeneratedValue(strategy = GenerationType.SEQUENCE ,generator="my_seq") private int id; @Column(name="name") String name; public Client() { // TODO Auto-generated constructor stub } //.... }
Code before change:
/** * insert new client. * @param client */ @Insert("INSERT INTO CLIENT(name) VALUES (#{name})") @Options(useGeneratedKeys=true, keyProperty="id") void insert(Client client);
1. Directly Remove @Options(useGeneratedKeys=true, keyProperty=”id”)
2. Replace @Options with @SelectKey:
/** * insert new client. * @param client */ @Insert("INSERT INTO CLIENT(name) VALUES (#{name})") @SelectKey( keyProperty = "id", before = true, resultType = Integer.class, statement={" select CLIENT_ID_SEQUENCE.nextval AS id from dual"} ) void insert(Client client);
Maven: modify the default JDK 修改Maven默认JDK <->
// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.