javax.persistence.MapsId Java Examples

The following examples show how to use javax.persistence.MapsId. 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 File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a @MapsId annotation to the specified annotationList if the specified element has the
 * maps-id attribute set. This should only be the case for many-to-one or one-to-one
 * associations.
 */
private void getMapsId(List<Annotation> annotationList, Element element) {
	String attrVal = element.attributeValue( "maps-id" );
	if ( attrVal != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( MapsId.class );
		ad.setValue( "value", attrVal );
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #2
Source File: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void addPropertyAnnotatedWithMapsId(XClass entityType, PropertyData property) {
	if ( propertiesAnnotatedWithMapsId == null ) {
		propertiesAnnotatedWithMapsId = new HashMap<>();
	}

	Map<String, PropertyData> map = propertiesAnnotatedWithMapsId.get( entityType );
	if ( map == null ) {
		map = new HashMap<>();
		propertiesAnnotatedWithMapsId.put( entityType, map );
	}
	map.put( property.getProperty().getAnnotation( MapsId.class ).value(), property );
}
 
Example #3
Source File: AnnotationBinder.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private static int addProperty(
		PropertyContainer propertyContainer,
		XProperty property,
		List<PropertyData> inFlightPropertyDataList,
		MetadataBuildingContext context) {
	// see if inFlightPropertyDataList already contains a PropertyData for this name,
	// and if so, skip it..
	for ( PropertyData propertyData : inFlightPropertyDataList ) {
		if ( propertyData.getPropertyName().equals( property.getName() ) ) {
			// EARLY EXIT!!!
			return 0;
		}
	}

	final XClass declaringClass = propertyContainer.getDeclaringClass();
	final XClass entity = propertyContainer.getEntityAtStake();
	int idPropertyCounter = 0;
	PropertyData propertyAnnotatedElement = new PropertyInferredData(
			declaringClass,
			property,
			propertyContainer.getClassLevelAccessType().getType(),
			context.getBootstrapContext().getReflectionManager()
	);

	/*
	 * put element annotated by @Id in front
	 * since it has to be parsed before any association by Hibernate
	 */
	final XAnnotatedElement element = propertyAnnotatedElement.getProperty();
	if ( element.isAnnotationPresent( Id.class ) || element.isAnnotationPresent( EmbeddedId.class ) ) {
		inFlightPropertyDataList.add( 0, propertyAnnotatedElement );
		/**
		 * The property must be put in hibernate.properties as it's a system wide property. Fixable?
		 * TODO support true/false/default on the property instead of present / not present
		 * TODO is @Column mandatory?
		 * TODO add method support
		 */
		if ( context.getBuildingOptions().isSpecjProprietarySyntaxEnabled() ) {
			if ( element.isAnnotationPresent( Id.class ) && element.isAnnotationPresent( Column.class ) ) {
				String columnName = element.getAnnotation( Column.class ).name();
				for ( XProperty prop : declaringClass.getDeclaredProperties( AccessType.FIELD.getType() ) ) {
					if ( !prop.isAnnotationPresent( MapsId.class ) ) {
						/**
						 * The detection of a configured individual JoinColumn differs between Annotation
						 * and XML configuration processing.
						 */
						boolean isRequiredAnnotationPresent = false;
						JoinColumns groupAnnotation = prop.getAnnotation( JoinColumns.class );
						if ( (prop.isAnnotationPresent( JoinColumn.class )
								&& prop.getAnnotation( JoinColumn.class ).name().equals( columnName )) ) {
							isRequiredAnnotationPresent = true;
						}
						else if ( prop.isAnnotationPresent( JoinColumns.class ) ) {
							for ( JoinColumn columnAnnotation : groupAnnotation.value() ) {
								if ( columnName.equals( columnAnnotation.name() ) ) {
									isRequiredAnnotationPresent = true;
									break;
								}
							}
						}
						if ( isRequiredAnnotationPresent ) {
							//create a PropertyData fpr the specJ property holding the mapping
							PropertyData specJPropertyData = new PropertyInferredData(
									declaringClass,
									//same dec
									prop,
									// the actual @XToOne property
									propertyContainer.getClassLevelAccessType().getType(),
									//TODO we should get the right accessor but the same as id would do
									context.getBootstrapContext().getReflectionManager()
							);
							context.getMetadataCollector().addPropertyAnnotatedWithMapsIdSpecj(
									entity,
									specJPropertyData,
									element.toString()
							);
						}
					}
				}
			}
		}

		if ( element.isAnnotationPresent( ManyToOne.class ) || element.isAnnotationPresent( OneToOne.class ) ) {
			context.getMetadataCollector().addToOneAndIdProperty( entity, propertyAnnotatedElement );
		}
		idPropertyCounter++;
	}
	else {
		inFlightPropertyDataList.add( propertyAnnotatedElement );
	}
	if ( element.isAnnotationPresent( MapsId.class ) ) {
		context.getMetadataCollector().addPropertyAnnotatedWithMapsId( entity, propertyAnnotatedElement );
	}

	return idPropertyCounter;
}
 
Example #4
Source File: RaceAwards.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
@OneToOne(mappedBy = "awards")
@MapsId
@JoinColumn(name="race_id")  
public Race getRace() {
    return race;
}
 
Example #5
Source File: AgeGroups.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
@OneToOne(mappedBy = "ageGroups")
@MapsId
@JoinColumn(name="race_id")  
public Race getRace() {
    return race;
}
 
Example #6
Source File: UseCase3.java    From celerio-angular-quickstart with Apache License 2.0 4 votes vote down vote up
@JoinColumn(name = "ID2", nullable = false)
@ManyToOne
@MapsId(value = "id2")
public UseCase2 getId2() {
    return id2;
}