Example usage for javax.persistence CascadeType ALL

List of usage examples for javax.persistence CascadeType ALL

Introduction

In this page you can find the example usage for javax.persistence CascadeType ALL.

Prototype

CascadeType ALL

To view the source code for javax.persistence CascadeType ALL.

Click Source Link

Document

Cascade all operations

Usage

From source file:no.abmu.questionnarie.domain.ReportDataOrgUnitMapping.java

/**
 * unique_key="unique_orgunitid_repdata"
 *
 * @hibernate.set lazy="true"/*from   w  ww  . ja  v  a2  s .co m*/
 * cascade="save-update"
 * table="FINANCE_REPDATA_ORGUNIT_MAPPING_REPORT_DATA"
 * @hibernate.key column="FK_MAPPING_ID"
 * @hibernate.many-to-many class="no.abmu.finances.domain.MainReportData"
 * column="FK_REPORT_DATA_ID"
 * @hibernate.collection-key column="FK_MAPPING_ID"
 * @hibernate.collection-many-to-many class="no.abmu.finances.domain.MainReportData"
 * column="FK_REPORT_DATA_ID"
 */
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@JoinColumn(name = "ORGUNIT_MAPPING_ID")
@NotNull
public Set<MainReportData> getReportDatas() {
    return reportDatas;
}

From source file:ca.mcgill.cs.swevo.qualyzer.model.Project.java

/**
 * @return the memos//from   w  w w  .  j a  va 2  s. com
 */
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
@JoinColumn(name = "project_persistenceid", nullable = false)
@OrderColumn(name = "index")
public List<Memo> getMemos() {
    return fMemos;
}

From source file:com.hmsinc.epicenter.model.geography.State.java

/**
 * @return the counties//from   w w  w  . j  av a 2s .c om
 */
@XmlElementWrapper(name = "counties", namespace = "http://epicenter.hmsinc.com/model")
@XmlElement(name = "county", namespace = "http://epicenter.hmsinc.com/model")
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY, mappedBy = "state")
@Where(clause = "type = 'C'")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE, region = "com.hmsinc.epicenter.model.GeographyCache")
@Sort(type = SortType.NATURAL)
public Set<County> getCounties() {
    return counties;
}

From source file:com.evolveum.midpoint.repo.sql.data.audit.RAuditEventRecord.java

@ForeignKey(name = "fk_audit_delta")
@OneToMany(mappedBy = "record", orphanRemoval = true)
@Cascade({ org.hibernate.annotations.CascadeType.ALL })
public Set<RObjectDeltaOperation> getDeltas() {
    if (deltas == null) {
        deltas = new HashSet<RObjectDeltaOperation>();
    }//from ww  w  .  j  a va 2 s  . c  om
    return deltas;
}

From source file:no.abmu.questionnarie.domain.MainReportData.java

/**
 * @hibernate.map table="FINANCE_REPORT_DATA_LIST"  cascade="all"
 * @hibernate.key column="FK_SUBREPDATA_ID"
 * @hibernate.index column="code"/*from  w  w w  .  j av  a 2  s . c  o m*/
 * type="string"
 * @hibernate.one-to-many class="no.abmu.finances.domain.SubReportDataList"
 * @hibernate.cache usage="nonstrict-read-write"
 * @hibernate.collection-key column="FK_SUBREPDATA_ID"
 * @hibernate.collection-index column="code"
 * type="string"
 * @hibernate.collection-one-to-many class="no.abmu.finances.domain.SubReportDataList"
 * @ hibernate.collection-cache usage="nonstrict-read-write"
 */

@OneToMany(cascade = CascadeType.ALL)
@MapKey(name = "key")
@JoinColumn(name = "mrd_fk")
public Map<String, SubReportDataList> getReportDataList() {
    return reportDataList;
}

From source file:com.evolveum.midpoint.repo.sql.data.common.any.RAssignmentExtension.java

@OneToMany(mappedBy = RAExtValue.ANY_CONTAINER, orphanRemoval = true)
@Cascade({ org.hibernate.annotations.CascadeType.ALL })
public Set<RAExtString> getStrings() {
    if (strings == null) {
        strings = new HashSet<>();
    }/*from www  .  ja  va 2s.c o m*/
    return strings;
}

From source file:com.impetus.kundera.persistence.EntityResolver.java

/**
 * helper method to recursively build reachable object list.
 * /*from  w ww.  jav a 2s  .  co m*/
 * @param object
 *            the o
 * @param cascadeType
 *            the cascade type
 * @param entities
 *            the entities
 * @param persistenceUnits
 *            the persistence units
 * @return the all reachable entities
 * @throws PropertyAccessException
 *             the property access exception
 */
private static void recursivelyResolveEntities(Object object, CascadeType cascadeType,
        Map<String, EnhancedEntity> entities) throws PropertyAccessException {

    EntityMetadata entityMetaData = null;
    entityMetaData = KunderaMetadataManager.getEntityMetadata(object.getClass());

    if (entityMetaData == null) {
        return;
    }

    String id = PropertyAccessorHelper.getId(object, entityMetaData);

    // Ensure that @Id is set
    if (null == id || id.trim().isEmpty()) {
        throw new ReaderResolverException("Missing primary key >> " + entityMetaData.getEntityClazz().getName()
                + "#" + entityMetaData.getIdColumn().getField().getName());
    }

    // Dummy name to check if the object is already processed
    String mapKeyForEntity = entityMetaData.getEntityClazz().getName() + "_" + id;

    if (entities.containsKey(mapKeyForEntity)) {
        return;
    }

    LOG.debug("Resolving >> " + mapKeyForEntity);

    // Map to hold property-name=>foreign-entity relations
    Map<String, Set<String>> foreignKeysMap = new HashMap<String, Set<String>>();

    // Save to map
    entities.put(mapKeyForEntity, getEnhancedEntity(object, id, foreignKeysMap));

    // Iterate over EntityMetata.Relation relations
    for (Relation relation : entityMetaData.getRelations()) {

        // Cascade?
        if (!relation.getCascades().contains(CascadeType.ALL)
                && !relation.getCascades().contains(cascadeType)) {
            continue;
        }

        // Target entity
        Class<?> targetClass = relation.getTargetEntity();
        // Mapped to this property
        Field targetField = relation.getProperty();
        // Is it optional?
        boolean optional = relation.isOptional();

        // Value
        Object value = PropertyAccessorHelper.getObject(object, targetField);

        // if object is not null, then proceed
        if (null != value) {
            EntityMetadata relMetadata = KunderaMetadataManager.getEntityMetadata(targetClass);

            if (relation.isUnary()) {
                // Unary relation will have single target object.
                String targetId = PropertyAccessorHelper.getId(value, relMetadata);

                Set<String> foreignKeys = new HashSet<String>();

                foreignKeys.add(targetId);
                // put to map
                foreignKeysMap.put(targetField.getName(), foreignKeys);

                // get all other reachable objects from object "value"
                recursivelyResolveEntities(value, cascadeType, entities);

            }
            if (relation.isCollection()) {
                // Collection relation can have many target objects.

                // Value must map to Collection interface.
                @SuppressWarnings("unchecked")
                Collection collection = (Collection) value;

                Set<String> foreignKeys = new HashSet<String>();

                // Iterate over each Object and get the @Id
                for (Object o_ : collection) {
                    String targetId = PropertyAccessorHelper.getId(o_, relMetadata);

                    foreignKeys.add(targetId);

                    // Get all other reachable objects from "o_"
                    recursivelyResolveEntities(o_, cascadeType, entities);
                }
                foreignKeysMap.put(targetField.getName(), foreignKeys);
            }
        }

        // if the value is null
        else {
            // halt, if this was a non-optional property
            if (!optional) {
                throw new ReaderResolverException(
                        "Missing " + targetClass.getName() + "." + targetField.getName());
            }
        }
    }
}

From source file:edu.scripps.fl.pubchem.db.PCAssayResult.java

@OneToOne(cascade = CascadeType.ALL)
public PCCurve getCurve() {
    return curve;
}

From source file:com.dhenton9000.birt.persistence.entities.ProductLines.java

@OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "ID", nullable = false)
@JsonManagedReference/*from  w ww . j a  v  a 2 s.  co  m*/
public Set<Products> getProducts() {

    return this.products;
}

From source file:uk.nhs.cfh.dsp.srth.information.model.impl.om.ehr.EHRImpl.java

/**
 * Gets the features./*w  ww.j  a  v a  2s  . c o m*/
 *
 * @return the features
 */
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = ClinicalFeatureEntry.class)
@JoinTable(name = "EHR_FEATURES", joinColumns = @JoinColumn(name = PATIENT_ID), inverseJoinColumns = @JoinColumn(name = "feature_id"))
@ForeignKey(name = "FK_EHR_FEA", inverseName = "FK_FEA_EHR")
public Set<BoundClinicalEntry> getFeatures() {
    return features;
}