I use Scaffolding in MyEclipse to generate Web Application project, using spring MVC and MySQL database. Please give me some clues to solve problem bellow.
I get problem with id primary key. It doesn't auto increment event if i use:
@GeneratedValue(strategy=GenerationType.IDENTITY)
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy=GenerationType.SEQUENCE)
@GeneratedValue(strategy=GenerationType.TABLE)I have several tables with the primary key set to AUTO_INCREMENT. Like this example:
Code:
CREATE TABLE IF NOT EXISTS `ehealthdb`.`timestamp` (
`id` BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '',
`login_date` DATETIME NULL COMMENT '',
`logout_date` DATETIME NULL COMMENT '',
`create_date` DATETIME NOT NULL COMMENT '',
`update_date` DATETIME NULL COMMENT '',
`isActive` TINYINT(1) NULL COMMENT '',
PRIMARY KEY (`id`) COMMENT '')
ENGINE = InnoDB;
When I try to use the save using the generated post URL and the following json payload:
Code:
{
"loginDate":"1374839856000",
"logoutDate":"1374839856000",
"createDate":"1374839856000",
"updateDate":"1374839856000",
"isActive":true
}
Quote:
> Request processing failed; nested exception is javax.persistence.PersistenceException:
org.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling save():
ehealth.domain.Timestamp
I think this is caused by a missing @GeneratedValue, which scaffolding has not created on my primary keys. I had to add it in manually like below:
But It's still not work. It's still get error.
Code:
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY) //add this
@Column(name = "id", unique = true, nullable = false)
@Basic(fetch = FetchType.EAGER)
@XmlElement
Integer id;