2015-08-30 19 views
0

的我想堅持這個實體,聲明的java不能persis實體,也許是因爲布爾場

@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([email protected]) 
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

您是否嘗試過直接在數據庫中執行此查詢?你有一個DML查詢,因爲它是由jpa執行的,你有所有的值,現在如果你試圖自己做,只是連接到你的數據庫,那麼你可以改變或排除一些值來找到那些值,這會導致異常。 – Stanislav

+0

@karimmohsen REPEAT是錯誤的,類別是一個實體(電力是ID),所以它是全部設置。 – usertest

+0

@斯坦尼斯拉夫感謝男人花時間,我修復它 – usertest

回答

4

我通過重命名列REPEAT反覆修復,因爲REPEAT是一個保留在mysql中工作的。

相關問題