引起:java.sql.SQLException:更新调用未设置generated-id键

时间:2015-12-12 13:26:02

标签: java sqlite ormlite

我正在尝试将Object存储到H2 / SQLite数据库。 Child类声明如下:

DatabaseTable(tableName = "pos_order_details", daoClass = PosOrderDetailsDaoImpl.class)
public class PosOrderDetails {

    @DatabaseField(generatedId = true, columnName = POS_ORDER_DETAILS_ID)
    private int posOrdersDetailsId;

    @SerializedName("price")
    @Expose
    @DatabaseField(columnName = PRICE)
    private double price;

子项在父项中定义如下,具有外来关系:

@SerializedName("pos_order_details")
@Expose
@ForeignCollectionField
private Collection<PosOrderDetails> posOrderDetails = new ArrayList<>(); 

大多数时候它的工作正常,但在一些随机的情况下,它给出了以下例外:

java.sql.SQLException: Unable to run insert stmt on object com.limetray.pos.models.PosOrderDetails@64031751: INSERT INTO `pos_order_details` (`price` ,`product_id` ,`product_price_id` ,`product_description` ,`product_name` ,`tag_name` ,`quantity` ,`complimentary_quantity` ,`charge_group_id` ,`user_comments` ,`pos_order_id` ) VALUES (?,?,?,?,?,?,?,?,?,?,?)
        at com.j256.ormlite.misc.SqlExceptionUtil.create(SqlExceptionUtil.java:22)
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:135)
        at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450)
        at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310)
        at com.limetray.pos.dbmanagers.implementations.PosOrderDetailsDaoImpl.insert(PosOrderDetailsDaoImpl.java:39)
        at com.limetray.pos.dbmanagers.implementations.PosOrderDaoImpl.insert(PosOrderDaoImpl.java:118)
        at com.limetray.pos.controllers.BillingSectionController.lambda$savePosOrderInDB$13(BillingSectionController.java:825)
        at com.limetray.pos.utilities.SingleTaskExecutor$1.call(SingleTaskExecutor.java:36)
        at javafx.concurrent.Task$TaskCallable.call(Unknown:-1)
        at java.util.concurrent.FutureTask.run(Unknown:-1)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown:-1)
        at java.util.concurrent.FutureTask.run(Unknown:-1)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown:-1)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown:-1)
        at java.lang.Thread.run(Unknown:-1)
Caused by: java.sql.SQLException: generated-id key was not set by the update call
        at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:115)
        at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450)
        at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310)
        at com.limetray.pos.dbmanagers.implementations.PosOrderDetailsDaoImpl.insert(PosOrderDetailsDaoImpl.java:39)
        at com.limetray.pos.dbmanagers.implementations.PosOrderDaoImpl.insert(PosOrderDaoImpl.java:118)
        at com.limetray.pos.controllers.BillingSectionController.lambda$savePosOrderInDB$13(BillingSectionController.java:825)
        at com.limetray.pos.utilities.SingleTaskExecutor$1.call(SingleTaskExecutor.java:36)
        at javafx.concurrent.Task$TaskCallable.call(Unknown:-1)
        at java.util.concurrent.FutureTask.run(Unknown:-1)
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown:-1)
        at java.util.concurrent.FutureTask.run(Unknown:-1)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown:-1)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown:-1)
        at java.lang.Thread.run(Unknown:-1)

0 个答案:

没有答案