Project

General

Profile

Revision f08b6366

IDf08b6366b1c48878484bf2c60f3ef346ce1e75a6
Parent a53c0e28
Child 4c2a3c2c

Added by Andreas Kohlbecker almost 2 years ago

ref #8064 ref #7648 autocreation of missing default secRef value in cdm preference model.taxonGraph.secRefUuid/

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxonGraph/AbstractHibernateTaxonGraphProcessor.java
24 24
import eu.etaxonomy.cdm.model.name.Rank;
25 25
import eu.etaxonomy.cdm.model.name.TaxonName;
26 26
import eu.etaxonomy.cdm.model.reference.Reference;
27
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27 28
import eu.etaxonomy.cdm.model.reference.ReferenceType;
28 29
import eu.etaxonomy.cdm.model.taxon.Taxon;
29 30
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
......
95 96
            Query q = getSession().createQuery("SELECT r FROM Reference r WHERE r.uuid = :uuid");
96 97
            q.setParameter("uuid", getSecReferenceUUID());
97 98
            secReference = (Reference) q.uniqueResult();
99
            if(secReference == null){
100
                Reference missingRef = ReferenceFactory.newGeneric();
101
                UUID uuid = getSecReferenceUUID();
102
                if(uuid != null){
103
                    missingRef.setUuid(uuid);
104
                } else {
105
                    throw new RuntimeException("cdm preference " + TaxonGraphDaoHibernateImpl.CDM_PREF_KEY_SEC_REF_UUID.getSubject() + TaxonGraphDaoHibernateImpl.CDM_PREF_KEY_SEC_REF_UUID.getPredicate() + " missing, can not recover");
106
                }
107
                missingRef.setTitle("Autocreated missing reference for cdm property" + TaxonGraphDaoHibernateImpl.CDM_PREF_KEY_SEC_REF_UUID.getSubject() + TaxonGraphDaoHibernateImpl.CDM_PREF_KEY_SEC_REF_UUID.getPredicate());
108
                logger.warn("A reference with " + getSecReferenceUUID() + " does not exist in the database, and thus will be created now with the title "
109
                        + "\"" + missingRef.getTitle() + "\"");
110
                getSession().merge(missingRef);
111
            }
98 112
        } else {
99 113
            // make sure the entity is still in the current session
100 114
            secReference = getSession().load(Reference.class, secReference.getId());

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)