我正试图坚持这个实体,声明
@Entity
@Table(schema="app")
public class Remainder {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private int amount;
private String description;
private boolean repeat;
@ManyToOne
@JoinColumn(name="CATEGORY")
private Category category;
@Column(name="DUE_DATE")
private LocalDate dueDate;
我使用EntityManager的persist()方法。我得到了这个例外:
[EL Warning]: 2015-08-30 11:14:56.341--UnitOfWork(1824877389)--Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): 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 'REPEAT, CATEGORY) VALUES (35, 'qeqdfqd', '2015-08-31', 0, 'Electricity')' at line 1
Error Code: 1064
Call: INSERT INTO app.REMAINDER (AMOUNT, DESCRIPTION, DUE_DATE, REPEAT, CATEGORY) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
Query: InsertObjectQuery(lite.money.entities.Remainder@326db21e)
Exception in thread "JavaFX Application Thread" javax.persistence.RollbackException: Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.0.v20150309-bf26070): 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 'REPEAT, CATEGORY) VALUES (35, 'qeqdfqd', '2015-08-31', 0, 'Electricity')' at line 1
Error Code: 1064
Call: INSERT INTO app.REMAINDER (AMOUNT, DESCRIPTION, DUE_DATE, REPEAT, CATEGORY) VALUES (?, ?, ?, ?, ?)
bind => [5 parameters bound]
这是表格声明
CREATE TABLE `remainder` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`amount` int(11) NOT NULL,
`description` varchar(100) NOT NULL,
`repeat` bit(1) DEFAULT NULL,
`category` varchar(100) NOT NULL,
`DUE_DATE` varchar(45) NOT NULL,
PRIMARY KEY (`id`),
KEY `FK_REMAINDER-Category_CATEGORY_SUB-ID_idx` (`category`),
CONSTRAINT `FK_REMAINDER-Category_CATEGORY_SUB-ID` FOREIGN KEY (`category`) REFERENCES `category` (`SUB_CATEGORY`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我认为问题在于布尔字段,请帮助
答案 0 :(得分:4)
我通过将列REPEAT重命名为重复来修复它,因为REPEAT是在mysql中保留的。