在失败的连接上避免空指针 [英] Avoiding null pointer on failed join

查看:111
本文介绍了在失败的连接上避免空指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  class Atendimento实现了Serializable {
...
Funcionario funcionario

静态映射= {
...
funcionario列:'FUNCODIGO',sqlType:'int'
}

static namedQueries = {
atendimentosPorData {data - >
data.clearTime();
eq('dataHora',data)
isNotNull('funcionario')
}
}
}
pre>

应用程序在没有FK约束的传统数据库上运行。
问题:存在一些中断的关系,一些Atendimento在数据库上有一个FUNCODIGO,但没有带这个标识符的Funcionario。
我可以查询没有问题,但是当我发送这个视图,像这样

  $ {fieldValue(bean :atendimentoInstance,field:funcionario)} 

我得到一个错误,说Grails无法找到 Funcionario,id:xxxxx。

条件中的 isNotNUll 不起作用,因为该列有数据,但在尝试解析连接时失败。



有没有一种方法可以防止在有问题的列上加入。

p>您可以使用 ignoreNotFound 来告诉Grails忽略缺少的引用

文档



ignoreNotFound strong>:
$ b


指定引用缺失行的外键在多对一关系中的处理方式。




  class LegacyCdDomain {
字符串标题
缩略图缩略图

静态映射= {
缩略图ignoreNotFound:true
}
}


I have my domain class, with a named query:

class Atendimento implements Serializable {
    ...
    Funcionario funcionario

    static mapping = {
        ...
        funcionario column: 'FUNCODIGO', sqlType: 'int'
    }

    static namedQueries = {
         atendimentosPorData { data ->
             data.clearTime();
             eq('dataHora', data)
             isNotNull('funcionario')
         }
    }
}

Application run on a legacy database with no FK constraints. The problem: there are some "broken" relationships, some "Atendimento" have a FUNCODIGO on the database, but there is no "Funcionario" with this identifier. I can query without problem, but when i send this to a view, like this

${fieldValue(bean: atendimentoInstance, field: "funcionario")}

I got a error saying that grails could not find "Funcionario" with id: xxxxx.
The isNotNUll on the criteria doesn't work because the column have data, but it fails when you try to resolve the join.

Is there a way to prevent the join on the "problematic" columns.

解决方案

You can use ignoreNotFound to tell Grails ignore the missing references

Documentation

ignoreNotFound:

Specifies how foreign keys that reference missing rows are handled in many-to-one relationships.

class LegacyCdDomain {
    String title
    Thumbnail thumbnail

    static mapping = {
        thumbnail ignoreNotFound: true
    }
}

这篇关于在失败的连接上避免空指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆