/**
* Insert an instance of Contact into the database.
* @param contact the instance to be persisted.
*/
@Insert(INSERT)
@Options(useGeneratedKeys = false, keyProperty = "id")
void insert(Contact contact);
/**
* Insert an instance of Contact into the database.
* @param contact the instance to be persisted.
*/
public void insert(Contact contact){
SqlSession session = sqlSessionFactory.openSession();
try {
ContactMapper mapper = session.getMapper(ContactMapper.class);
mapper.insert(contact);
session.commit();
} finally {
session.close();
}
}
class Contact {
private int id;
private String name;
private String phone;
private String email;
//gets and setters
...
CREATE TABLE `blog`.`contact` (
`CONTACT_ID` int(11) NOT NULL AUTO_INCREMENT,
`CONTACT_EMAIL` varchar(255) NOT NULL,
`CONTACT_NAME` varchar(255) NOT NULL,
`CONTACT_PHONE` varchar(255) NOT NULL,
PRIMARY KEY (`CONTACT_ID`)
)
ENGINE=InnoDB;
Alguem saberia me dizer porque
não retorna o ID no objeto apos fazer um Insert?
sempre retorna 0