gpt4 book ai didi

java 无法保留一个实体,可能是因为 boolean 字段

转载 作者:行者123 更新时间:2023-12-01 00:41:06 29 4
gpt4 key购买 nike

我试图持久化这个实体,声明

@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() 方法。我得到这个异常(exception):

[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;

我认为问题出在 boolean 字段上,请帮助

最佳答案

我通过将列 REPEAT 重命名为 repeated 来修复它,因为 REPEAT 是 mysql 中的保留项。

关于java 无法保留一个实体,可能是因为 boolean 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32296068/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com