Example usage for javax.persistence FetchType EAGER

List of usage examples for javax.persistence FetchType EAGER

Introduction

In this page you can find the example usage for javax.persistence FetchType EAGER.

Prototype

FetchType EAGER

To view the source code for javax.persistence FetchType EAGER.

Click Source Link

Document

Defines that data must be eagerly fetched.

Usage

From source file:org.apache.openjpa.persistence.AnnotationPersistenceMetaDataSerializer.java

/**
 * Add many-to-many attributes./*from w  w w . ja  v  a  2 s  .  com*/
 */
private void addManyToManyAttributes(FieldMetaData fmd, AnnotationBuilder ab) {
    if (fmd.isInDefaultFetchGroup())
        ab.add("fetch", FetchType.EAGER);
    addTargetEntityAttribute(fmd, ab);
}

From source file:org.batoo.jpa.core.impl.model.mapping.AssociationMapping.java

/**
 * @param parent// w w  w  . jav a  2 s  . co  m
 *            the parent mapping
 * @param metadata
 *            the metadata
 * @param attribute
 *            the attribute
 * 
 * @since $version
 * @author hceylan
 */
public AssociationMapping(ParentMapping<?, Z> parent, AssociationAttributeMetadata metadata,
        AttributeImpl<? super Z, X> attribute) {
    super(parent, attribute, attribute.getJavaType(), attribute.getName());

    if ((metadata instanceof MappableAssociationAttributeMetadata)
            && StringUtils.isNotBlank(((MappableAssociationAttributeMetadata) metadata).getMappedBy())) {
        this.mappedBy = ((MappableAssociationAttributeMetadata) metadata).getMappedBy();
    } else {
        this.mappedBy = null;
    }

    this.eager = attribute.isCollection() || (this.mappedBy == null)
            ? metadata.getFetchType() == FetchType.EAGER
            : true;

    if (metadata instanceof OrphanableAssociationAttributeMetadata) {
        this.removesOrphans = ((OrphanableAssociationAttributeMetadata) metadata).removesOrphans();
    } else {
        this.removesOrphans = false;
    }

    this.cascadesDetach = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.DETACH);
    this.cascadesMerge = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.MERGE);
    this.cascadesPersist = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.PERSIST);
    this.cascadesRefresh = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.REFRESH);
    this.cascadesRemove = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.REMOVE);
}

From source file:org.batoo.jpa.core.impl.model.mapping.AssociationMappingImpl.java

/**
 * @param parent/*from   w  ww .ja  v  a2s  .com*/
 *            the parent mapping
 * @param metadata
 *            the metadata
 * @param attribute
 *            the attribute
 * 
 * @since 2.0.0
 */
public AssociationMappingImpl(AbstractParentMapping<?, Z> parent, AssociationAttributeMetadata metadata,
        AttributeImpl<? super Z, X> attribute) {
    super(parent, attribute, attribute.getJavaType(), attribute.getName());

    if ((metadata instanceof MappableAssociationAttributeMetadata)
            && StringUtils.isNotBlank(((MappableAssociationAttributeMetadata) metadata).getMappedBy())) {
        this.mappedBy = ((MappableAssociationAttributeMetadata) metadata).getMappedBy();
    } else {
        this.mappedBy = null;
    }

    this.eager = attribute.isCollection() || (this.mappedBy == null)
            ? metadata.getFetchType() == FetchType.EAGER
            : true;

    this.maxFetchDepth = metadata.getMaxFetchDepth();
    this.fetchStrategy = metadata.getFetchStrategy();

    if (metadata instanceof OrphanableAssociationAttributeMetadata) {
        this.removesOrphans = ((OrphanableAssociationAttributeMetadata) metadata).removesOrphans();
    } else {
        this.removesOrphans = false;
    }

    this.cascadesDetach = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.DETACH);
    this.cascadesMerge = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.MERGE);
    this.cascadesPersist = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.PERSIST);
    this.cascadesRefresh = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.REFRESH);
    this.cascadesRemove = metadata.getCascades().contains(CascadeType.ALL)
            || metadata.getCascades().contains(CascadeType.REMOVE);
}

From source file:org.batoo.jpa.core.impl.model.mapping.ElementCollectionMapping.java

/**
 * @param parent/*from  ww  w  . jav  a2 s.c  om*/
 *            the parent mapping
 * @param attribute
 *            the attribute
 * 
 * @since $version
 * @author hceylan
 */
public ElementCollectionMapping(ParentMapping<?, Z> parent, PluralAttributeImpl<? super Z, C, E> attribute) {
    super(parent, attribute, attribute.getJavaType(), attribute.getName());

    final ElementCollectionAttributeMetadata metadata = (ElementCollectionAttributeMetadata) attribute
            .getMetadata();

    this.attribute = attribute;
    this.eager = metadata.getFetchType() == FetchType.EAGER;

    this.collectionTable = new CollectionTable((EntityTypeImpl<?>) this.getRoot().getType(),
            metadata.getCollectionTable());
    this.column = metadata.getColumn();
    this.enumType = metadata.getEnumType();
    this.lob = metadata.isLob();
    this.temporalType = metadata.getTemporalType();

    if (this.attribute.getCollectionType() == CollectionType.LIST) {
        this.orderColumn = metadata.getOrderColumn();
        this.orderBy = metadata.getOrderBy();
    } else {
        this.orderBy = null;
        this.orderColumn = null;
    }

    if (this.attribute.getCollectionType() == CollectionType.MAP) {
        this.mapKeyColumn = metadata.getMapKeyColumn();
        this.mapKeyTemporalType = metadata.getMapKeyTemporalType();
        this.mapKeyEnumType = metadata.getMapKeyEnumType();
        this.mapKey = metadata.getMapKey();
    } else {
        this.mapKeyColumn = null;
        this.mapKeyTemporalType = null;
        this.mapKeyEnumType = null;
        this.mapKey = null;
    }
}

From source file:org.batoo.jpa.core.impl.model.mapping.ElementCollectionMappingImpl.java

/**
 * @param parent/*from  www  .ja va2 s  . c  o  m*/
 *            the parent mapping
 * @param attribute
 *            the attribute
 * 
 * @since 2.0.0
 */
public ElementCollectionMappingImpl(AbstractParentMapping<?, Z> parent,
        PluralAttributeImpl<? super Z, C, E> attribute) {
    super(parent, attribute, attribute.getJavaType(), attribute.getName());

    final ElementCollectionAttributeMetadata metadata = (ElementCollectionAttributeMetadata) attribute
            .getMetadata();

    this.attribute = attribute;
    this.eager = metadata.getFetchType() == FetchType.EAGER;

    this.collectionTable = new CollectionTable(attribute.getMetamodel().getJdbcAdaptor(), this,
            metadata.getCollectionTable());
    this.column = metadata.getColumn();
    this.enumType = metadata.getEnumType();
    this.lob = metadata.isLob();
    this.temporalType = metadata.getTemporalType();

    if (this.attribute.getCollectionType() == CollectionType.LIST) {
        this.orderColumn = metadata.getOrderColumn();
        this.orderBy = metadata.getOrderBy();
    } else {
        this.orderBy = null;
        this.orderColumn = null;
    }

    if (this.attribute.getCollectionType() == CollectionType.MAP) {
        this.mapKeyColumn = metadata.getMapKeyColumn();
        this.mapKeyTemporalType = metadata.getMapKeyTemporalType();
        this.mapKeyEnumType = metadata.getMapKeyEnumType();
        this.mapKey = metadata.getMapKey();
    } else {
        this.mapKeyColumn = null;
        this.mapKeyTemporalType = null;
        this.mapKeyEnumType = null;
        this.mapKey = null;
    }
}

From source file:org.bonitasoft.engine.bdm.RelationFieldAnnotator.java

public void annotateRelationField(final JDefinedClass entityClass, final RelationField field,
        final JFieldVar fieldVar) {
    JAnnotationUse relation = null;/*w  ww  .ja va  2s . c  om*/
    if (field.isCollection()) {
        relation = annotateMultipleReference(entityClass, field, fieldVar);
    } else {
        relation = annotateSingleReference(field, fieldVar);
    }

    if (field.isLazy()) {
        relation.param("fetch", FetchType.LAZY);
        codeGenerator.addAnnotation(fieldVar, JsonIgnore.class);
    } else {
        relation.param("fetch", FetchType.EAGER);
    }

    if (field.getType() == Type.COMPOSITION) {
        relation.param("cascade", CascadeType.ALL);
    } else if (field.getType() == Type.AGGREGATION) {
        relation.param("cascade", CascadeType.MERGE);
    }
}

From source file:org.bonitasoft.engine.business.data.generator.RelationFieldAnnotator.java

public void annotateRelationField(final JDefinedClass entityClass, final RelationField field,
        final JFieldVar fieldVar) {
    JAnnotationUse relation = null;//from w  ww  . j a va2 s .  c  om
    if (field.isCollection()) {
        relation = annotateMultipleReference(entityClass, field, fieldVar);
    } else {
        relation = annotateSingleReference(entityClass, field, fieldVar);
    }

    if (field.isLazy()) {
        relation.param("fetch", FetchType.LAZY);
        codeGenerator.addAnnotation(fieldVar, JsonIgnore.class);
    } else {
        relation.param("fetch", FetchType.EAGER);
    }

    if (field.getType() == Type.COMPOSITION) {
        relation.param("cascade", CascadeType.ALL);
    } else if (field.getType() == Type.AGGREGATION) {
        relation.param("cascade", CascadeType.MERGE);
    }

}

From source file:org.carcv.core.model.file.FileEntry.java

/**
 * @return a list of FileCarImages of this FileEntry
 *///from ww  w. j a v a  2s . co  m
@Override
@NotNull
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, targetEntity = FileCarImage.class, orphanRemoval = true)
public List<FileCarImage> getCarImages() {
    return carImages;
}

From source file:org.eclipse.jubula.client.core.model.AUTConfigPO.java

/**
 * only for Persistence (JPA / EclipseLink)!
 * /*from  ww  w  .ja  va 2s  .c om*/
 * @return the config
 */
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "AUT_CONF_ATTR", joinColumns = @JoinColumn(name = "AUT_CONF"))
@MapKeyColumn(name = "ATTR_KEY")
@Column(name = "ATTR_VALUE", length = MAX_STRING_LENGTH)
Map<String, String> getHbmConfigMap() {
    return m_config;
}

From source file:org.eclipse.jubula.client.core.model.ExecTestCasePO.java

/**
 * only for Persistence (JPA / EclipseLink)
 * //from w w  w  .  j a v  a2 s  .  co  m
 * @return Returns the compNameMap.
 */
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER, targetEntity = CompNamesPairPO.class)
@MapKeyColumn(name = "MK_EXECTC_COMPNAMES")
@JoinColumn(name = "FK_EXECTC")
@BatchFetch(value = BatchFetchType.JOIN)
private Map<String, ICompNamesPairPO> getHbmCompNamesMap() {
    return m_compNamesMap;
}