"Fossies" - the Fresh Open Source Software Archive

Member "grails-core-5.2.4/grails-docs/src/test/resources/docs/ref/Database Mapping/ignoreNotFound.html" (14 Sep 2022, 60641 Bytes) of package /linux/www/grails-core-5.2.4.tar.gz:


Caution: In this restricted "Fossies" environment the current HTML page may not be correctly presentated and may have some non-functional links. You can here alternatively try to browse the pure source code or just view or download the uninterpreted raw source code. If the rendering is insufficient you may try to find and view the page on the grails-core-5.2.4.tar.gz project site itself.

(Quick Reference)

ignoreNotFound

Purpose

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

Examples

class LegacyCdDomain {

    String title
    Thumbnail thumbnail

    static mapping = {
        thumbnail ignoreNotFound: true
    }
}
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.

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.