////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////


== ignoreNotFound



=== Purpose


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


=== Examples


[source,groovy]
----
class LegacyCdDomain {

    String title
    Thumbnail thumbnail

    static mapping = {
        thumbnail ignoreNotFound: true
    }
}
----

[source,groovy]
----
class Thumbnail {
    byte[] data
}
----


=== Description


Usage: `association_name(ignoreNotFound: boolean)`

When the data in the database is corrupt and a foreign key references a non existent record, Hibernate will complain with a "No row with the given identifier exists" message. For example, a `LegacyCdDomain` record may have a reference to a `Thumbnail` record with an ID of 1234, but the database may no longer contain a `Thumbnail` with that ID.

One possible way to load such corrupt data is to use the `ignoreNotFound` mapping option. If you set it to `true`, Hibernate will treat a missing row as a `null` association. So in the above example, our `LegacyCdDomain` instance would load but its `thumbnail` property would be `null`. Specifying a value of `false` for `ignoreNotFound` will result in Hibernate throwing an `org.hibernate.ObjectNotFoundException`.

WARNING: A dataset loaded with `ignoreNotFound: true` may throw an exception during `save()` because of the missing reference!

The default value for this setting is `false`. It maps to Hibernate's `not-found` property.

This settings can be useful if you have a legacy database with unusual behaviour when it comes to referential integrity.
