0

RandomID 不能为空:

我有一个生成随机数的函数 RandomGen .. ItkTInventory 是我使用主样本详细信息表单创建 CRUD 时创建的数据库 java 文件。在执行保存按钮操作时,我想将生成的随机数插入到 mysql 中的数据库中。

private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           
    RandomGen rand = new RandomGen();
    ItkTInventory inventory = new ItkTInventory();
    inventory.setSRandomID(rand.randomCode());
    try {
        entityManager.getTransaction().commit();
        entityManager.getTransaction().begin();
    } catch (RollbackException rex) {
        rex.printStackTrace();
        entityManager.getTransaction().begin();
        List<barcode.ItkTInventory> merged = new ArrayList<barcode.ItkTInventory>(list.size());
        for (barcode.ItkTInventory i : list) {
            merged.add(entityManager.merge(i));
        }
        list.clear();
        list.addAll(merged);
    }
}                        
4

2 回答 2

0

发生此错误是因为您试图将空值插入非空字段。调试您的程序并确保 RandomID 值不为空

于 2013-03-19T06:47:37.993 回答
0

在这里,您尝试将声明为 not null 的 null 值放入数据库中。

SOLUTION:删除数据库中的非空值或不保存空值

于 2013-03-19T06:49:01.030 回答