Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 空实体字段使@PostUpdate方法自动停止_Jpa_Spring Mvc_Post Update - Fatal编程技术网

Jpa 空实体字段使@PostUpdate方法自动停止

Jpa 空实体字段使@PostUpdate方法自动停止,jpa,spring-mvc,post-update,Jpa,Spring Mvc,Post Update,我有一个JPA域实体,我正在根据用户输入更新它。取决于该对象的许多因素,它在更新时要执行一些操作(在本例中,更新是“将其标记为已完成”) 在数据库中,两个“完成后操作配置”字段(note和next_workflow)可为空,或者具有感兴趣的值,或者为空。可能有很多,但我从这两个开始 我在模型类中编写了以下方法: @PostUpdate public void gotUpdate() { System.out.println("Got post update for " + this.ge

我有一个JPA域实体,我正在根据用户输入更新它。取决于该对象的许多因素,它在更新时要执行一些操作(在本例中,更新是“将其标记为已完成”)

在数据库中,两个“完成后操作配置”字段(note和next_workflow)可为空,或者具有感兴趣的值,或者为空。可能有很多,但我从这两个开始

我在模型类中编写了以下方法:

@PostUpdate
public void gotUpdate() {
    System.out.println("Got post update for " + this.getDescription());
    if (! this.getNote().isEmpty()) {
        Note n = new Note();
        n.setAssetId(this.getAssetId());
        n.setNotifyLessor(1);
        n.setNote(this.getLessorNote() + this.getCapturedData());
        n.setCreatedDate(new Date());
        n.persist();
    }
    System.out.println("In the middle of post update for " + this.getDescription());
    if (this.getNextWorkflow() != 0) {
        Asset a = this.getAssetId();
        a.setWorkflowId(Workflow.findWorkflow(this.getNextWorkflow()));
        a.merge();          
    }
    System.out.println("Finishing post update for " + this.getDescription());
}
对于具有空“note”值的实体,控制台输出为:

Got post update for this item
Got post update for this item
In the middle of post update for this item
对于具有非NULL“note”值和NULL“nextWorkflow”值的实体,控制台输出为:

Got post update for this item
Got post update for this item
In the middle of post update for this item
任何地方都没有错误,没有堆栈转储,什么都没有。该方法只是静默退出,并且我正在对该实体执行的合并没有完成(数据库保持不变)


在调试器中单步执行这一操作会到达测试内容的那一行,如果该值为NULL,则会弹出一个选项卡,显示“Source not found”,我真的不知道该如何处理它。我想这只是调试器说它不能介入某些事情,但事实上我并没有要求它…

新手问题,事实证明

如果
对象
字段
字段为空,则
对象.getField().length()
是对空指针的调用

答案是测试字段的空值,而不是空值的副作用

if (! (this.getNote() == null)) {
...
}

事实证明,这是一个菜鸟问题

如果
对象
字段
字段为空,则
对象.getField().length()
是对空指针的调用

答案是测试字段的空值,而不是空值的副作用

if (! (this.getNote() == null)) {
...
}