当前位置: 首页>>代码示例>>Java>>正文


Java OneToOne类代码示例

本文整理汇总了Java中javax.persistence.OneToOne的典型用法代码示例。如果您正苦于以下问题:Java OneToOne类的具体用法?Java OneToOne怎么用?Java OneToOne使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OneToOne类属于javax.persistence包,在下文中一共展示了OneToOne类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isCascadeAll

import javax.persistence.OneToOne; //导入依赖的package包/类
private boolean isCascadeAll()
{
	OneToMany onetomany = getAnnotation(OneToMany.class);
	if( onetomany != null )
	{
		return hasCascadeAll(onetomany.cascade());
	}
	OneToOne onetoone = getAnnotation(OneToOne.class);
	if( onetoone != null )
	{
		return hasCascadeAll(onetoone.cascade());
	}
	ManyToOne manyToOne = getAnnotation(ManyToOne.class);
	if( manyToOne != null )
	{
		return hasCascadeAll(manyToOne.cascade());
	}
	// CollectionOfElements is a 'default' cascade all
	if( getAnnotation(CollectionOfElements.class) != null )
	{
		return true;
	}

	return false;
}
 
开发者ID:equella,项目名称:Equella,代码行数:26,代码来源:Property.java

示例2: getMappedBy

import javax.persistence.OneToOne; //导入依赖的package包/类
private String getMappedBy(MetaAttribute attr) {
	ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
	OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
	OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
	String mappedBy = null;
	if (manyManyAnnotation != null) {
		mappedBy = manyManyAnnotation.mappedBy();
	}
	if (oneManyAnnotation != null) {
		mappedBy = oneManyAnnotation.mappedBy();
	}
	if (oneOneAnnotation != null) {
		mappedBy = oneOneAnnotation.mappedBy();
	}

	if (mappedBy != null && mappedBy.length() == 0) {
		mappedBy = null;
	}
	return mappedBy;
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:21,代码来源:JpaMetaFilter.java

示例3: getFieldType

import javax.persistence.OneToOne; //导入依赖的package包/类
@Override
public Optional<ResourceFieldType> getFieldType(BeanAttributeInformation attributeDesc) {
	Optional<OneToOne> oneToOne = attributeDesc.getAnnotation(OneToOne.class);
	Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
	Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
	Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
	if (oneToOne.isPresent() || oneToMany.isPresent() || manyToOne.isPresent() || manyToMany.isPresent()) {
		return Optional.of(ResourceFieldType.RELATIONSHIP);
	}

	Optional<Id> id = attributeDesc.getAnnotation(Id.class);
	Optional<EmbeddedId> embeddedId = attributeDesc.getAnnotation(EmbeddedId.class);
	if (id.isPresent() || embeddedId.isPresent()) {
		return Optional.of(ResourceFieldType.ID);
	}
	return Optional.empty();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:18,代码来源:JpaResourceFieldInformationProvider.java

示例4: hasAnnotationsOnIdClass

import javax.persistence.OneToOne; //导入依赖的package包/类
private static boolean hasAnnotationsOnIdClass(XClass idClass) {
//		if(idClass.getAnnotation(Embeddable.class) != null)
//			return true;

		List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD );
		for ( XProperty property : properties ) {
			if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) ||
					property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) ||
					property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) ||
					property.isAnnotationPresent( ManyToMany.class )
					) {
				return true;
			}
		}
		List<XMethod> methods = idClass.getDeclaredMethods();
		for ( XMethod method : methods ) {
			if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) ||
					method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) ||
					method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) ||
					method.isAnnotationPresent( ManyToMany.class )
					) {
				return true;
			}
		}
		return false;
	}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:AnnotationBinder.java

示例5: nonInverseToOneAssociationsMustBeLazilyFetched

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * In JPA, @ManyToOne and @OneToOne associations are fetched eagerly by
 * default. That will, in most situations, cause performance problems.
 * Because of that, the default behavior shall be changed to lazy fetching
 * which this test enforces. On some rare occasions, the developer may want
 * to apply eager fetching and for these cases @EagerFetch annotation is
 * available for indicating that the intention is purposeful and should be
 * passed by this test.
 */
@Test
public void nonInverseToOneAssociationsMustBeLazilyFetched() {
    final Stream<Field> failedFields = filterFieldsOfManagedJpaTypes(field -> {
        final OneToOne oneToOne = field.getAnnotation(OneToOne.class);
        final ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);

        return !isIdField(field) && !field.isAnnotationPresent(EagerFetch.class) &&
                (manyToOne != null && manyToOne.fetch() == FetchType.EAGER ||
                        oneToOne != null && "".equals(oneToOne.mappedBy()) && oneToOne.fetch() == FetchType.EAGER);
    });

    assertNoFields(failedFields,
            "These entity fields should either have \"fetch = FetchType.LAZY\" parameter set on @ManyToOne/" +
                    "@OneToOne annotation or alternatively be annotated with @EagerFetch: ");
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:25,代码来源:JpaModelTest.java

示例6: appendEntityAttributeName

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * 
 * Append the entity attribute name to the JPQL query statement.
 * 
 * @param jpqlStatement
 * @param jpaEntity
 * @param attribute
 * @throws java.lang.SecurityException 
 * @throws NoSuchFieldException 
 * @throws ClassNotFoundException 
 */
private void appendEntityAttributeName(StringBuilder jpqlStatement, JpaEntity jpaEntity, EntityAttribute attribute, AtomicInteger aliasUnicityKey, AtomicInteger joinAdditionsOffset) throws NoSuchFieldException, java.lang.SecurityException, ClassNotFoundException {
	Class<?> entityClass = Class.forName(jpaEntity.getClassName());
	Field field = entityClass.getDeclaredField(attribute.getAttributeName());
	boolean isJointRelationship = 
			field.getAnnotation(OneToOne.class) != null
			|| field.getAnnotation(OneToMany.class) != null
			|| field.getAnnotation(ManyToOne.class) != null
			|| field.getAnnotation(ManyToMany.class) != null;
	if(isJointRelationship) {
		StringBuilder joinFragment = new StringBuilder();
		Queue<String> objectTreePath = extractDotSeparatedPathFragments(attribute.getPossibleValueLabelAttributePath());
		completeJoinFragment(joinFragment, entityClass, objectTreePath, aliasUnicityKey);
		jpqlStatement.insert(joinAdditionsOffset.get(), joinFragment);
		joinAdditionsOffset.set(joinAdditionsOffset.get() + joinFragment.length());
		jpqlStatement.append(" x").append(aliasUnicityKey.get()).append('.').append(attribute.getPossibleValueLabelAttribute());
	} else {
		jpqlStatement.append(" x.").append(attribute.getAttributeName());
	}
}
 
开发者ID:infiniquery,项目名称:infiniquery-core,代码行数:31,代码来源:DefaultQueryModelService.java

示例7: getValueType

import javax.persistence.OneToOne; //导入依赖的package包/类
protected Class<?> getValueType(PopulateValueRequest populateValueRequest, Class<?> startingValueType) {
    Class<?> valueType = startingValueType;
    if (!StringUtils.isEmpty(populateValueRequest.getMetadata().getToOneTargetProperty())) {
        Field nestedField = FieldManager.getSingleField(valueType, populateValueRequest.getMetadata()
                .getToOneTargetProperty());
        ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class);
        if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) {
            valueType = manyToOne.targetEntity();
        } else {
            OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
            if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) {
                valueType = oneToOne.targetEntity();
            }
        }
    }
    return valueType;
}
 
开发者ID:takbani,项目名称:blcdemo,代码行数:18,代码来源:MapFieldPersistenceProvider.java

示例8: anyAnnotation

import javax.persistence.OneToOne; //导入依赖的package包/类
private Annotation anyAnnotation(Field field) {
    Annotation annotation = null;

    annotation = field.getAnnotation(ManyToMany.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(OneToOne.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(OneToMany.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(ManyToOne.class);
    if (annotation != null) {
        return annotation;
    }

    return null;
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:26,代码来源:EntityRelationHelper.java

示例9: mappedByAnything

import javax.persistence.OneToOne; //导入依赖的package包/类
private Annotation mappedByAnything(String property) {
    Field field = findField(property);
    Annotation relationAnnotation = null;

    relationAnnotation = field.getAnnotation(ManyToMany.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(OneToOne.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(OneToMany.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(ManyToOne.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    return null;
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:27,代码来源:EntityRelationHelper.java

示例10: targetEntity

import javax.persistence.OneToOne; //导入依赖的package包/类
private Class<?> targetEntity(Annotation relationAnnotation) {
    if (relationAnnotation instanceof ManyToMany) {
        return ManyToMany.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof OneToOne) {
        return OneToOne.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof OneToMany) {
        return OneToMany.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof ManyToOne) {
        return ManyToOne.class.cast(relationAnnotation).targetEntity();
    }

    return null;
}
 
开发者ID:jurgendl,项目名称:hql-builder,代码行数:20,代码来源:EntityRelationHelper.java

示例11: configureExample

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * Metodo que agrega relaciones
 * 
 * @param criteria
 * @param example
 * @return
 */
@Nonnull
private Criteria configureExample(@Nonnull final Criteria criteria,
		final T example) {

	if (example == null) {
		return criteria;
	}
	try {
		for (final Field f : example.getClass().getDeclaredFields()) {
			f.setAccessible(true);
			if (f.getAnnotation(OneToOne.class) == null
					&& f.getAnnotation(ManyToOne.class) == null
					|| f.get(example) == null) {
				continue;
			}
			criteria.add(Restrictions.eq(f.getName(), f.get(example)));
		}
	} catch (final Exception e) {
		this.log.error("Error al agregar la relación", e);
	}
	return criteria;
}
 
开发者ID:fpuna-cia,项目名称:karaku,代码行数:30,代码来源:BaseDAOImpl.java

示例12: buildUniqueProperty

import javax.persistence.OneToOne; //导入依赖的package包/类
private void buildUniqueProperty(final SingularProperty<E, ?> property) {
	if (this.context.getMaxUniqueProperties() > 0) {
		final boolean unique;
		final Column column = property.getAttribute().getAnnotation(Column.class);
		if (column != null && column.unique()) {
			unique = true;
		} else {
			final OneToOne oneToOne = property.getAttribute().getAnnotation(OneToOne.class);
			if (oneToOne != null) {
				unique = StringUtils.isEmpty(oneToOne.mappedBy());
			} else {
				final JoinColumn joinColumn = property.getAttribute().getAnnotation(JoinColumn.class);
				unique = joinColumn != null && joinColumn.unique();
			}
		}
		if (unique) {
			final UniquePropertyQuality propertyQuality = UniquePropertyQuality.getMatchingQuality(property);
			if (propertyQuality != null && isBetterUniquePropertyQuality(propertyQuality)) {
				this.uniquePropertiesQuality = propertyQuality;
				this.uniqueProperties = Collections
						.<SingularProperty<E, ?>> singletonList((SingularProperty<E, ?>) property);
			}
		}
	}
}
 
开发者ID:liefke,项目名称:org.fastnate,代码行数:26,代码来源:EntityClass.java

示例13: isLazy

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * Find if a OneToOne or OneToMany annotation exits and if it's the case, verify if the fetch is LAZY.
 * @param field the field
 * @return true if eager, false otherwise
 */
public static boolean isLazy(final Field field) {
    final OneToOne oneOne = field.getAnnotation(OneToOne.class);
    if (oneOne != null) {
        // By Default Eager
        return oneOne.fetch().equals(FetchType.LAZY);
    }
    final ManyToOne manyOne = field.getAnnotation(ManyToOne.class);
    if (manyOne != null) {
        // By Default Eager
        return manyOne.fetch().equals(FetchType.LAZY);
    }
    final OneToMany oneMany = field.getAnnotation(OneToMany.class);
    if (oneMany != null) {
        // By Default Lazy
        return oneMany.fetch().equals(FetchType.LAZY);
    }
    final ManyToMany manyMany = field.getAnnotation(ManyToMany.class);
    if (manyMany != null) {
        // By Default Lazy
        return manyMany.fetch().equals(FetchType.LAZY);
    }
    // Other case, no problem
    return true;
}
 
开发者ID:qjafcunuas,项目名称:jbromo,代码行数:30,代码来源:EntityUtil.java

示例14: getTargetEntityFromAnnotation

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * @param field
 * @return
 */
private static Class<?> getTargetEntityFromAnnotation(final Field field)
{
	for (final Annotation annotation : field.getAnnotations())
	{
		if (instanceOf(annotation, OneToMany.class))
		{
			return ((OneToMany) annotation).targetEntity();
		}
		else if (instanceOf(annotation, OneToOne.class))
		{
			return ((OneToOne) annotation).targetEntity();
		}
	}
	return null;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:20,代码来源:JpaAnnotationUtil.java

示例15: extractPropertyMetadata

import javax.persistence.OneToOne; //导入依赖的package包/类
/**
 * Get the property metadata
 * for the supplied property
 * @param property
 * @param builder
 */
@SuppressWarnings("unchecked")
private void extractPropertyMetadata(PropertyDescriptor property, ResourceMetadataBuilder builder) {
	// Get the field for the property
	Method accessor = property.getReadMethod();
	
	// Get the property name
	String name = property.getName();

	// Is it an identity field?
	if (AnnotationHelper.fieldOrPropertyAnnotated(property, Id.class)) {
		builder.identityProperty(name, accessor);
	}

	// Is it a relation field (and therefore embedded)?
	else if (AnnotationHelper.fieldOrPropertyAnnotated(property, ManyToOne.class, OneToOne.class, OneToMany.class, ManyToMany.class)) {
		builder.embeddedResource(name, accessor);
	}

	// None of the above, must be @Basic or unadorned.
	else {
		builder.simpleProperty(name, accessor);
	}
}
 
开发者ID:patrickvankann,项目名称:bjug-querydsl,代码行数:30,代码来源:JpaEntityResourceMetadataExtractor.java


注:本文中的javax.persistence.OneToOne类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。