Java Code Examples for javax.persistence.ElementCollection

The following examples show how to use javax.persistence.ElementCollection. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crnk-framework   Source File: AbstractEntityMetaFactory.java    License: Apache License 2.0 6 votes vote down vote up
protected boolean isJpaLazy(Collection<Annotation> annotations, boolean isAssociation) {
	for (Annotation annotation : annotations) {
		if (annotation instanceof OneToMany) {
			OneToMany oneToMany = (OneToMany) annotation;
			return oneToMany.fetch() == FetchType.LAZY;
		}
		if (annotation instanceof ManyToOne) {
			ManyToOne manyToOne = (ManyToOne) annotation;
			return manyToOne.fetch() == FetchType.LAZY;
		}
		if (annotation instanceof ManyToMany) {
			ManyToMany manyToMany = (ManyToMany) annotation;
			return manyToMany.fetch() == FetchType.LAZY;
		}
		if (annotation instanceof ElementCollection) {
			ElementCollection elementCollection = (ElementCollection) annotation;
			return elementCollection.fetch() == FetchType.LAZY;
		}
	}
	return isAssociation;
}
 
Example 2
@Override
public Optional<SerializeType> getSerializeType(BeanAttributeInformation attributeDesc) {
    Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
    if (oneToMany.isPresent()) {
        return toSerializeType(oneToMany.get().fetch());
    }
    Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
    if (manyToOne.isPresent()) {
        return toSerializeType(manyToOne.get().fetch());
    }
    Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
    if (manyToMany.isPresent()) {
        return toSerializeType(manyToMany.get().fetch());
    }
    Optional<ElementCollection> elementCollection = attributeDesc.getAnnotation(ElementCollection.class);
    if (elementCollection.isPresent()) {
        return toSerializeType(elementCollection.get().fetch());
    }
    return Optional.empty();
}
 
Example 3
Source Project: lams   Source File: CollectionBinder.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static void bindCollectionSecondPass(
		Collection collValue,
		PersistentClass collectionEntity,
		Ejb3JoinColumn[] joinColumns,
		boolean cascadeDeleteEnabled,
		XProperty property,
		PropertyHolder propertyHolder,
		MetadataBuildingContext buildingContext) {
	try {
		BinderHelper.createSyntheticPropertyReference(
				joinColumns,
				collValue.getOwner(),
				collectionEntity,
				collValue,
				false,
				buildingContext
		);
	}
	catch (AnnotationException ex) {
		throw new AnnotationException( "Unable to map collection " + collValue.getOwner().getClassName() + "." + property.getName(), ex );
	}
	SimpleValue key = buildCollectionKey( collValue, joinColumns, cascadeDeleteEnabled, property, propertyHolder, buildingContext );
	if ( property.isAnnotationPresent( ElementCollection.class ) && joinColumns.length > 0 ) {
		joinColumns[0].setJPA2ElementCollection( true );
	}
	TableBinder.bindFk( collValue.getOwner(), collectionEntity, joinColumns, key, false, buildingContext );
}
 
Example 4
/**
 * As per sections 12.2.3.23.9, 12.2.4.8.9 and 12.2.5.3.6 of the JPA 2.0
 * specification, the element-collection subelement completely overrides the
 * mapping for the specified field or property.  Thus, any methods which
 * might in some contexts merge with annotations must not do so in this
 * context.
 */
private void getElementCollection(List<Annotation> annotationList, XMLContext.Default defaults) {
	for ( Element element : elementsForProperty ) {
		if ( "element-collection".equals( element.getName() ) ) {
			AnnotationDescriptor ad = new AnnotationDescriptor( ElementCollection.class );
			addTargetClass( element, ad, "target-class", defaults );
			getFetchType( ad, element );
			getOrderBy( annotationList, element );
			getOrderColumn( annotationList, element );
			getMapKey( annotationList, element );
			getMapKeyClass( annotationList, element, defaults );
			getMapKeyTemporal( annotationList, element );
			getMapKeyEnumerated( annotationList, element );
			getMapKeyColumn( annotationList, element );
			buildMapKeyJoinColumns( annotationList, element );
			Annotation annotation = getColumn( element.element( "column" ), false, element );
			addIfNotNull( annotationList, annotation );
			getTemporal( annotationList, element );
			getEnumerated( annotationList, element );
			getLob( annotationList, element );
			//Both map-key-attribute-overrides and attribute-overrides
			//translate into AttributeOverride annotations, which need
			//need to be wrapped in the same AttributeOverrides annotation.
			List<AttributeOverride> attributes = new ArrayList<>();
			attributes.addAll( buildAttributeOverrides( element, "map-key-attribute-override" ) );
			attributes.addAll( buildAttributeOverrides( element, "attribute-override" ) );
			annotation = mergeAttributeOverrides( defaults, attributes, false );
			addIfNotNull( annotationList, annotation );
			annotation = getAssociationOverrides( element, defaults, false );
			addIfNotNull( annotationList, annotation );
			getCollectionTable( annotationList, element, defaults );
			annotationList.add( AnnotationFactory.create( ad ) );
			getAccessType( annotationList, element );
		}
	}
}
 
Example 5
Source Project: metacat   Source File: Info.java    License: Apache License 2.0 5 votes vote down vote up
@ElementCollection
@MapKeyColumn(name = "parameters_idx")
@Column(name = "parameters_elt")
@CollectionTable(name = "info_parameters")
public Map<String, String> getParameters() {
    return parameters;
}
 
Example 6
Source Project: mycore   Source File: MCRUser.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "MCRUserAttr",
    joinColumns = @JoinColumn(name = "id"),
    indexes = { @Index(name = "MCRUserAttributes", columnList = "name, value"),
        @Index(name = "MCRUserValues", columnList = "value") })
@SortNatural
@XmlElementWrapper(name = "attributes")
@XmlElement(name = "attribute")
public SortedSet<MCRUserAttribute> getAttributes() {
    return this.attributes;
}
 
Example 7
Source Project: mycore   Source File: MCRJob.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns all set parameters of the job.
 * 
 * @return the job parameters
 */
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "MCRJobParameter", joinColumns = @JoinColumn(name = "jobID"))
@MapKeyColumn(name = "paramKey", length = 128)
@Column(name = "paramValue", length = 255)
public Map<String, String> getParameters() {
    return parameters;
}
 
Example 8
Source Project: mycore   Source File: MCRCategoryImpl.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "MCRCategoryLabels",
    joinColumns = @JoinColumn(name = "category"),
    uniqueConstraints = {
        @UniqueConstraint(columnNames = { "category", "lang" }) })
public Set<MCRLabel> getLabels() {
    return super.getLabels();
}
 
Example 9
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="timing_location_input_attributes", [email protected](name="tli_id"))
@OrderColumn(name = "index_id")
public Map<String, String> getAttributes() {
    //System.out.println("TLI.getAttributes called, returning " + attributes.size() + " attributes");
    return attributes;
}
 
Example 10
Source Project: pikatimer   Source File: Bib2ChipMap.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="chip", insertable=false,updatable=false)
@Column(name="bib")
@CollectionTable(name="bib2chipmap", [email protected](name="bib2chip_id"))
public Map<String, String> getChip2BibMap() {
    //System.out.println("TLI.getAttributes called, returning " + attributes.size() + " attributes");
    return chip2bibMap;
}
 
Example 11
Source Project: pikatimer   Source File: Participant.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute_id")
@Column(name="attribute_value")
@CollectionTable(name="participant_attributes", [email protected](name="participant_id"))
public Map<Integer,String> getCustomAttributes(){
    return customAttributeMap;
}
 
Example 12
Source Project: pikatimer   Source File: Participant.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
    @Column(name="wave_id", nullable=false)
    @CollectionTable(name="part2wave", [email protected](name="participant_id"))
//    @OrderColumn(name = "index_id")
    public Set<Integer> getWaveIDs() {
        return waveIDSet;  
    }
 
Example 13
Source Project: pikatimer   Source File: EventOptions.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="event_options_attributes", [email protected](name="event_id"))
//@OrderColumn(name = "index_id")
private Map<String, String> getAttributes() {
    System.out.println("EventOptions::getAttributes()");
    attributes.keySet().forEach(k -> {
    System.out.println("  " + k + " -> " + attributes.get(k));
    });
    return attributes;
}
 
Example 14
Source Project: pikatimer   Source File: AwardCategory.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
      name="race_award_category_depths",
      [email protected](name="ac_id")
)
protected List<AwardDepth> getCustomDepthList(){
    return customDepthList;
}
 
Example 15
Source Project: pikatimer   Source File: AwardCategory.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
      name="race_award_category_filters",
      [email protected](name="ac_id")
)
protected List<AwardFilter> getFilterList(){
    return filters;
}
 
Example 16
Source Project: pikatimer   Source File: AwardCategory.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
      name="race_award_category_subdivide_list",
      [email protected](name="ac_id")
)
@Column(name="attribute")
protected Set<String> getSubDivideList(){
    return splitBy;
}
 
Example 17
Source Project: pikatimer   Source File: RaceAwards.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@OneToMany(mappedBy="raceAward",cascade={CascadeType.PERSIST, CascadeType.REMOVE},fetch = FetchType.EAGER)
@Fetch(FetchMode.SELECT)
@OrderColumn(name = "category_priority")
public List<AwardCategory> getAwardCategories(){
    return awardCategories;
}
 
Example 18
Source Project: pikatimer   Source File: RaceAwards.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_awards_attributes", [email protected](name="race_id"))
@OrderColumn(name = "index_id")
private Map<String, String> getAttributes() {
    return attributes;
}
 
Example 19
Source Project: pikatimer   Source File: AgeGroups.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(
      name="race_age_group_increments",
      [email protected](name="ag_id")
)
protected List<AgeGroupIncrement> getCustomIncrementsList(){
    return customIncrementList;
}
 
Example 20
Source Project: pikatimer   Source File: Race.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_attributes", [email protected](name="race_id"))
private Map<String, String> getAttributes() {
    return attributes;
}
 
Example 21
Source Project: pikatimer   Source File: RaceReport.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="attribute", insertable=false,updatable=false)
@Column(name="value")
@CollectionTable(name="race_output_attributes", [email protected](name="output_id"))
@OrderColumn(name = "id")
private Map<String, String> getAttributes() {
    return attributes;
}
 
Example 22
Source Project: pikatimer   Source File: Result.java    License: GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@MapKeyColumn(name="split_id", insertable=false,updatable=false)
@Column(name="split_time",nullable=false)
@CollectionTable(name="split_results", [email protected](name="result_id"))
public Map<Integer,Long> getSplitMap(){
    return splitMap;
}
 
Example 23
private boolean hasJpaAnnotations(MetaAttribute attribute) {
	List<Class<? extends Annotation>> annotationClasses = Arrays.asList(Id.class, EmbeddedId.class, Column.class,
			ManyToMany.class, ManyToOne.class, OneToMany.class, OneToOne.class, Version.class,
			ElementCollection.class);
	for (Class<? extends Annotation> annotationClass : annotationClasses) {
		if (attribute.getAnnotation(annotationClass) != null) {
			return true;
		}
	}
	return false;
}
 
Example 24
Source Project: scheduling   Source File: TaskData.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "TASK_DATA_DEPENDENCIES", joinColumns = { @JoinColumn(name = "JOB_ID", referencedColumnName = "TASK_ID_JOB"),
                                                                  @JoinColumn(name = "TASK_ID", referencedColumnName = "TASK_ID_TASK") }, indexes = { @Index(name = "TASK_DATA_DEP_JOB_ID", columnList = "JOB_ID"),
                                                                                                                                                      @Index(name = "TASK_DATA_DEP_TASK_ID_JOB_ID", columnList = "TASK_ID,JOB_ID"),
                                                                                                                                                      @Index(name = "TASK_DATA_DEP_TASK_ID", columnList = "TASK_ID"), })
@BatchSize(size = 100)
public List<DBTaskId> getDependentTasks() {
    return dependentTasks;
}
 
Example 25
Source Project: scheduling   Source File: TaskData.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "TASK_DATA_JOINED_BRANCHES", joinColumns = { @JoinColumn(name = "JOB_ID", referencedColumnName = "TASK_ID_JOB"),
                                                                     @JoinColumn(name = "TASK_ID", referencedColumnName = "TASK_ID_TASK") }, indexes = { @Index(name = "TASK_DATA_JB_JOB_ID", columnList = "JOB_ID"),
                                                                                                                                                         @Index(name = "TASK_DATA_JB_TASK_ID_JOB_ID", columnList = "TASK_ID,JOB_ID"),
                                                                                                                                                         @Index(name = "TASK_DATA_JB_TASK_ID", columnList = "TASK_ID"), })
@BatchSize(size = 100)
public List<DBTaskId> getJoinedBranches() {
    return joinedBranches;
}
 
Example 26
Source Project: website   Source File: User.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(targetClass = Role.class, fetch = FetchType.EAGER)
@CollectionTable(name = "USER_ROLES", joinColumns = @JoinColumn(name = "USER_ID"))
@Enumerated(EnumType.STRING)
@Column(name = "role", nullable = false)
public Set<Role> getRoles() {
	return roles;
}
 
Example 27
Source Project: website   Source File: User.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(targetClass = Permission.class, fetch = FetchType.EAGER)
@CollectionTable(name = "USER_PERMISSIONS", joinColumns = @JoinColumn(name = "USER_ID"))
@Enumerated(EnumType.STRING)
@Column(name = "permission", nullable = false)
public Set<Permission> getPermissions() {
	return permissions;
}
 
Example 28
Source Project: lams   Source File: ColumnsBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
public ColumnsBuilder extractMetadata() {
	columns = null;
	joinColumns = buildExplicitJoinColumns(property, inferredData);


	if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( Formula.class ) ) {
		Column ann = property.getAnnotation( Column.class );
		Formula formulaAnn = property.getAnnotation( Formula.class );
		columns = Ejb3Column.buildColumnFromAnnotation(
				new Column[] { ann },
				formulaAnn,
				nullability,
				propertyHolder,
				inferredData,
				entityBinder.getSecondaryTables(),
				buildingContext
		);
	}
	else if ( property.isAnnotationPresent( Columns.class ) ) {
		Columns anns = property.getAnnotation( Columns.class );
		columns = Ejb3Column.buildColumnFromAnnotation(
				anns.columns(),
				null,
				nullability,
				propertyHolder,
				inferredData,
				entityBinder.getSecondaryTables(),
				buildingContext
		);
	}

	//set default values if needed
	if ( joinColumns == null &&
			( property.isAnnotationPresent( ManyToOne.class )
					|| property.isAnnotationPresent( OneToOne.class ) )
			) {
		joinColumns = buildDefaultJoinColumnsForXToOne(property, inferredData);
	}
	else if ( joinColumns == null &&
			( property.isAnnotationPresent( OneToMany.class )
					|| property.isAnnotationPresent( ElementCollection.class )
			) ) {
		OneToMany oneToMany = property.getAnnotation( OneToMany.class );
		String mappedBy = oneToMany != null ?
				oneToMany.mappedBy() :
				"";
		joinColumns = Ejb3JoinColumn.buildJoinColumns(
				null,
				mappedBy,
				entityBinder.getSecondaryTables(),
				propertyHolder,
				inferredData.getPropertyName(),
				buildingContext
		);
	}
	else if ( joinColumns == null && property.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
		throw new AnnotationException( "@Any requires an explicit @JoinColumn(s): "
				+ BinderHelper.getPath( propertyHolder, inferredData ) );
	}
	if ( columns == null && !property.isAnnotationPresent( ManyToMany.class ) ) {
		//useful for collection of embedded elements
		columns = Ejb3Column.buildColumnFromAnnotation(
				null,
				null,
				nullability,
				propertyHolder,
				inferredData,
				entityBinder.getSecondaryTables(),
				buildingContext
		);
	}

	if ( nullability == Nullability.FORCED_NOT_NULL ) {
		//force columns to not null
		for (Ejb3Column col : columns ) {
			col.forceNotNull();
		}
	}
	return this;
}
 
Example 29
Source Project: lams   Source File: CollectionBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void defineFetchingStrategy() {
	LazyCollection lazy = property.getAnnotation( LazyCollection.class );
	Fetch fetch = property.getAnnotation( Fetch.class );
	OneToMany oneToMany = property.getAnnotation( OneToMany.class );
	ManyToMany manyToMany = property.getAnnotation( ManyToMany.class );
	ElementCollection elementCollection = property.getAnnotation( ElementCollection.class );
	ManyToAny manyToAny = property.getAnnotation( ManyToAny.class );
	FetchType fetchType;
	if ( oneToMany != null ) {
		fetchType = oneToMany.fetch();
	}
	else if ( manyToMany != null ) {
		fetchType = manyToMany.fetch();
	}
	else if ( elementCollection != null ) {
		fetchType = elementCollection.fetch();
	}
	else if ( manyToAny != null ) {
		fetchType = FetchType.LAZY;
	}
	else {
		throw new AssertionFailure(
				"Define fetch strategy on a property not annotated with @ManyToOne nor @OneToMany nor @CollectionOfElements"
		);
	}
	if ( lazy != null ) {
		collection.setLazy( !( lazy.value() == LazyCollectionOption.FALSE ) );
		collection.setExtraLazy( lazy.value() == LazyCollectionOption.EXTRA );
	}
	else {
		collection.setLazy( fetchType == FetchType.LAZY );
		collection.setExtraLazy( false );
	}
	if ( fetch != null ) {
		if ( fetch.value() == org.hibernate.annotations.FetchMode.JOIN ) {
			collection.setFetchMode( FetchMode.JOIN );
			collection.setLazy( false );
		}
		else if ( fetch.value() == org.hibernate.annotations.FetchMode.SELECT ) {
			collection.setFetchMode( FetchMode.SELECT );
		}
		else if ( fetch.value() == org.hibernate.annotations.FetchMode.SUBSELECT ) {
			collection.setFetchMode( FetchMode.SELECT );
			collection.setSubselectLoadable( true );
			collection.getOwner().setSubselectLoadableCollections( true );
		}
		else {
			throw new AssertionFailure( "Unknown FetchMode: " + fetch.value() );
		}
	}
	else {
		collection.setFetchMode( AnnotationBinder.getFetchMode( fetchType ) );
	}
}
 
Example 30
/**
 * look for @OneToMany, @ManyToMany and @ElementCollection annotations
 */
@Override
public boolean isMappedCollection(UnloadedField field) {
	return field.hasAnnotation( OneToMany.class ) || field.hasAnnotation( ManyToMany.class )  || field.hasAnnotation( ElementCollection.class );
}