0

I am trying to persist an object using the entity manager in a springboot application.

but I am getting the below exception

Caused by: java.sql.SQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'interval, last_updated) values ('5MIN', '2023-02-01 00:56:16')' at line 1
Query is : insert into cms_kpi_config (interval, last_updated) values ('5MIN', '2023-02-01 00:56:16.0')
at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:125)
at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
at org.mariadb.jdbc.MariaDbStatement.executeQueryEpilog(MariaDbStatement.java:242)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeInternal(MariaDbClientPreparedStatement.java:210)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeUpdate(MariaDbClientPreparedStatement.java:186)
at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:384)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
... 223 more
Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'interval, last_updated) values ('5MIN', '2023-02-01 00:56:16')' at line 1
Query is : insert into cms_kpi_config (interval, last_updated) values ('5MIN', '2023-02-01 00:56:16.0')
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:939)
at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQueries(AbstractQueryProtocol.java:775)
at org.mariadb.jdbc.MariaDbClientPreparedStatement.executeInternal(MariaDbClientPreparedStatement.java:201)
... 226 more

I don't seem to understand what the problem is.

here is my table definition

CREATE TABLE IF NOT EXISTS `cms_kpi_config` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`interval` enum('5MIN','30MIN','60MIN') NOT NULL DEFAULT '5MIN',
`last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

here is my Entity

@Entity
@Table(name = "cms_kpi_config")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CmsKPIConfig {

private Integer id;
private String interval;
private Date lastUpdated;

@Id
@Column(name = "id", nullable = false, unique = true)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
    return id;
}

public void setId(Integer id) {
    this.id = id;
}

@Column(name = "interval", nullable = false)
@NotNull
public String getInterval() {
    return interval;
}

public void setInterval(String interval) {
    this.interval = interval;
}

@Column(name = "last_updated")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date getLastUpdated() {
    return lastUpdated;
}

public void setLastUpdated(Date lastUpdated) {
    this.lastUpdated = lastUpdated;
}
}

In my Dao service class, I'm using entitymanager as below.

private EntityManager manager;
this.manager.persist(obj);

enter image description here

Please help

2
  • Just a guess - interval is a keyword in MySQL/MariaDB Jan 31, 2023 at 14:27
  • reported as CONJ-1048
    – danblack
    Jan 31, 2023 at 22:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.