Field 'ID' doesn't have a default value

245
November 28, 2016, at 7:32 PM

I am using MySQL with Hibernate and JPA2.

I have the following table, which I would expect to auto generate the ID because AI (Auto Increment) is checked:

CREATE TABLE `job` (
  `ID` int(11) NOT NULL AUTO_INCREMENT,
  `JOINING_DATE` double NOT NULL,
  `LASTACCESS_DATE` double NOT NULL,
  `PHONE_NUMBER` varchar(55) DEFAULT NULL,
  `MOBILE_NUMBER` varchar(55) DEFAULT NULL,
  `EMAIL_ADDRESS` varchar(55) DEFAULT NULL,
  `SEX` int(1) DEFAULT NULL,
  `JOB_TITLE` varchar(65) NOT NULL,
  `JOB_DESCRIPTION` varchar(800) NOT NULL,
  `JOB_DETAILS` varchar(800) DEFAULT NULL,
  `DRIVERS_LICENCE` int(1) DEFAULT NULL,
  `AVATAR` longblob,
  `TYPE` int(1) NOT NULL,
  PRIMARY KEY (`ID`),
  UNIQUE KEY `ID_UNIQUE` (`ID`)
) ENGINE=MyISAM AUTO_INCREMENT=87 DEFAULT CHARSET=utf8;

Job.java

@Entity
@Table(name = "job")
@XmlRootElement(name = "job")
public class Job extends AbstractDomain<Long> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    ...

Dao.java

protected T merge(T entity) throws InstantiationException, IllegalAccessException {
    T attached = null;
    if (entity.getId() != null) {
        attached = entityManager.find(entityClass, entity.getId());
    }
    if (attached == null) {
        attached = entityClass.newInstance(); // <= this is executed
    }
    BeanUtils.copyProperties(entity, attached);
    entityManager.merge(attached); // <= ID is null here
    return attached;
}

When I try merge the table, I get the following error:

Caused by: java.sql.SQLException: Field 'ID' doesn't have a default value

Strange thing is this was working earlier, and the Java code has not changed, I did make changes to some other database tables only. I have read here that some people had this problem and fixed it by dropping and importing their database. I did drop the schema and imported it again. But still get the same error.

Does anyone have any ideas please?

READ ALSO
Cancel makemigrations Django

Cancel makemigrations Django

I'm developping a website in django but yesterday i did bad thing with my models

294
Fullpage.js + HTML5 History API

Fullpage.js + HTML5 History API

I am looking to save history changes using the HTML5 pushState API calls when a slide change occurs using fullpagejs

358