I have a simple table in MySQL and i want to persist data in it via JPA , but i get an error describing below, what is wrong here ?
the application is hosted in GlassFish 4, using MySQL 5 and EJB please consider below table's definition
CREATE TABLE `myproject`.`detected_issues` (
`sdate` datetime NOT NULL default '0000-00-00 00:00:00',
`pxvalue` double NOT NULL default '0',
`generation` varchar(6) NOT NULL ,
`schema` varchar(30) NOT NULL ,
`node` varchar(100) NOT NULL,
`parent` varchar(100) NOT NULL ,
`layer` varchar(30) NOT NULL ,
`interval` varchar(5) NOT NULL ,
`id` int(10) unsigned NOT NULL auto_increment ,
PRIMARY KEY (`id`),
UNIQUE KEY `detected_issues_UIDX` (`sdate`,`node`,`generation`,`schema`,`layer`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
and this is the entity class
@Entity
@Table(name="detected_issues")
@NamedQuery(name="DetectedIssue.findAll", query="SELECT d FROM DetectedIssue d")
public class DetectedIssue implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String generation;
private String interval;
private String layer;
private String node;
private String parent;
private double pxvalue;
private String schema;
@Temporal(TemporalType.TIMESTAMP)
private Date sdate;
public DetectedIssue() {
}
}
with following code i get an error described at below
@PersistenceContext(unitName = "ADProjectEJB")
private EntityManager em;
DetectedIssue issuet = new DetectedIssue();
issuet.setNode("Node");
issuet.setParent("Parent");
issuet.setPxvalue(0.5d);
issuet.setGeneration("Gen");
issuet.setSchema("HU");
issuet.setLayer("Layer");
issuet.setInterval("AH");
issuet.setSdate(Calendar.getInstance().getTime());
System.out.println(issuet.toString());
em.persist(issuet);
em.flush();
the Error
Caused by: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INTERVAL, LAYER, NODE, PARENT, PXVALUE, SCHEMA, SDATE) VALUES ('Gen', 'AH', 'Lay' at line 1 Error Code: 1064 Call: INSERT INTO detected_issues (GENERATION, INTERVAL, LAYER, NODE, PARENT, PXVALUE, SCHEMA, SDATE) VALUES (?, ?, ?, ?, ?, ?, ?, ?) bind => [8 parameters bound]