类javax.persistence.OneToOne源码实例Demo

下面列出了怎么用javax.persistence.OneToOne的API类实例代码及写法,或者点击链接到github查看源代码。

private boolean getCascade(ManyToMany manyManyAnnotation, ManyToOne manyOneAnnotation, OneToMany oneManyAnnotation,
						   OneToOne oneOneAnnotation) {
	if (manyManyAnnotation != null) {
		return getCascade(manyManyAnnotation.cascade());
	}
	if (manyOneAnnotation != null) {
		return getCascade(manyOneAnnotation.cascade());
	}
	if (oneManyAnnotation != null) {
		return getCascade(oneManyAnnotation.cascade());
	}
	if (oneOneAnnotation != null) {
		return getCascade(oneOneAnnotation.cascade());
	}
	return false;
}
 
@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();
}
 
源代码3 项目: lams   文件: AnnotationBinder.java
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;
	}
 
源代码4 项目: lams   文件: PersistentAttributesHelper.java
private static String getMappedByFromAnnotation(CtField persistentField) {

		OneToOne oto = PersistentAttributesHelper.getAnnotation( persistentField, OneToOne.class );
		if ( oto != null ) {
			return oto.mappedBy();
		}

		OneToMany otm = PersistentAttributesHelper.getAnnotation( persistentField, OneToMany.class );
		if ( otm != null ) {
			return otm.mappedBy();
		}

		// For @ManyToOne associations, mappedBy must come from the @OneToMany side of the association

		ManyToMany mtm = PersistentAttributesHelper.getAnnotation( persistentField, ManyToMany.class );
		return mtm == null ? "" : mtm.mappedBy();
	}
 
源代码5 项目: lams   文件: BiDirectionalAssociationHandler.java
private static String getMappedByNotManyToMany(FieldDescription target) {
	try {
		AnnotationDescription.Loadable<OneToOne> oto = EnhancerImpl.getAnnotation( target, OneToOne.class );
		if ( oto != null ) {
			return oto.getValue( new MethodDescription.ForLoadedMethod( OneToOne.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class );
		}

		AnnotationDescription.Loadable<OneToMany> otm = EnhancerImpl.getAnnotation( target, OneToMany.class );
		if ( otm != null ) {
			return otm.getValue( new MethodDescription.ForLoadedMethod( OneToMany.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class );
		}

		AnnotationDescription.Loadable<ManyToMany> mtm = EnhancerImpl.getAnnotation( target, ManyToMany.class );
		if ( mtm != null ) {
			return mtm.getValue( new MethodDescription.ForLoadedMethod( ManyToMany.class.getDeclaredMethod( "mappedBy" ) ) ).resolve( String.class );
		}
	}
	catch (NoSuchMethodException ignored) {
	}

	return null;
}
 
源代码6 项目: cuba   文件: SoftDeleteJoinExpressionProvider.java
@Override
protected Expression processOneToOneMapping(OneToOneMapping mapping) {
    ClassDescriptor descriptor = mapping.getDescriptor();
    Field referenceField = FieldUtils.getAllFieldsList(descriptor.getJavaClass())
            .stream().filter(f -> f.getName().equals(mapping.getAttributeName()))
            .findFirst().orElse(null);
    if (SoftDelete.class.isAssignableFrom(mapping.getReferenceClass()) && referenceField != null) {
        OneToOne oneToOne = referenceField.getAnnotation(OneToOne.class);
        if (oneToOne != null && !Strings.isNullOrEmpty(oneToOne.mappedBy())) {
            return new ExpressionBuilder().get("deleteTs").isNull();
        }
    }
    return null;
}
 
源代码7 项目: scheduling   文件: TaskData.java
@Cascade(CascadeType.ALL)
@OneToOne(fetch = FetchType.LAZY)
// disable foreign key, to be able to remove runtime data
@JoinColumn(name = "CLEAN_SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getCleanScript() {
    return cleanScript;
}
 
源代码8 项目: jdal   文件: JpaUtils.java
/**
 * Gets the mappedBy value from an attribute
 * @param attribute attribute
 * @return mappedBy value or null if none.
 */
public static String getMappedBy(Attribute<?, ?> attribute) {
	String mappedBy = null;
	
	if (attribute.isAssociation()) {
		Annotation[] annotations = null;
		Member member = attribute.getJavaMember();
		if (member instanceof Field) {
			annotations = ((Field) member).getAnnotations();
		}
		else if (member instanceof Method) {
			annotations = ((Method) member).getAnnotations();
		}
		
		for (Annotation a : annotations) {
			if (a.annotationType().equals(OneToMany.class)) {
				mappedBy = ((OneToMany) a).mappedBy();
				break;
			}
			else if (a.annotationType().equals(ManyToMany.class)) {
				mappedBy = ((ManyToMany) a).mappedBy();
				break;
			}
			else if (a.annotationType().equals(OneToOne.class)) {
				mappedBy = ((OneToOne) a).mappedBy();
				break;
			}
		}
	}
	
	return "".equals(mappedBy) ? null : mappedBy;
}
 
源代码9 项目: scheduling   文件: TaskData.java
@Cascade(org.hibernate.annotations.CascadeType.ALL)
@OneToOne(fetch = FetchType.LAZY)
// disable foreign key, to be able to remove runtime data
@JoinColumn(name = "ENV_SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getEnvScript() {
    return envScript;
}
 
@Override
protected RelationshipRepositoryBehavior getDefaultRelationshipRepositoryBehavior(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() || manyToOne.isPresent() || oneToMany.isPresent() || manyToMany.isPresent()) {
		Optional<String> mappedBy = getMappedBy(attributeDesc);
		if (mappedBy.isPresent() && mappedBy.get().length() > 0) {
			return RelationshipRepositoryBehavior.FORWARD_OPPOSITE;
		}
		return RelationshipRepositoryBehavior.FORWARD_OWNER;
	}
	return RelationshipRepositoryBehavior.DEFAULT;
}
 
源代码11 项目: scheduling   文件: TaskData.java
@Cascade(CascadeType.ALL)
@OneToOne(fetch = FetchType.LAZY)
// disable foreign key, to be able to remove runtime data
@JoinColumn(name = "FLOW_SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getFlowScript() {
    return flowScript;
}
 
源代码12 项目: lams   文件: ColumnsBuilder.java
Ejb3JoinColumn[] buildDefaultJoinColumnsForXToOne(XProperty property, PropertyData inferredData) {
	Ejb3JoinColumn[] joinColumns;
	JoinTable joinTableAnn = propertyHolder.getJoinTable( property );
	if ( joinTableAnn != null ) {
		joinColumns = Ejb3JoinColumn.buildJoinColumns(
				joinTableAnn.inverseJoinColumns(),
				null,
				entityBinder.getSecondaryTables(),
				propertyHolder,
				inferredData.getPropertyName(),
				buildingContext
		);
		if ( StringHelper.isEmpty( joinTableAnn.name() ) ) {
			throw new AnnotationException(
					"JoinTable.name() on a @ToOne association has to be explicit: "
							+ BinderHelper.getPath( propertyHolder, inferredData )
			);
		}
	}
	else {
		OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class );
		String mappedBy = oneToOneAnn != null
				? oneToOneAnn.mappedBy()
				: null;
		joinColumns = Ejb3JoinColumn.buildJoinColumns(
				null,
				mappedBy,
				entityBinder.getSecondaryTables(),
				propertyHolder,
				inferredData.getPropertyName(),
				buildingContext
		);
	}
	return joinColumns;
}
 
源代码13 项目: lams   文件: ToOneBinder.java
private static Class<?> getTargetEntityClass(XProperty property) {
	final ManyToOne mTo = property.getAnnotation( ManyToOne.class );
	if (mTo != null) {
		return mTo.targetEntity();
	}
	final OneToOne oTo = property.getAnnotation( OneToOne.class );
	if (oTo != null) {
		return oTo.targetEntity();
	}
	throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() );
}
 
源代码14 项目: lams   文件: AnnotationBinder.java
private static boolean isIdClassPkOfTheAssociatedEntity(
		InheritanceState.ElementsToProcess elementsToProcess,
		XClass compositeClass,
		PropertyData inferredData,
		PropertyData baseInferredData,
		AccessType propertyAccessor,
		Map<XClass, InheritanceState> inheritanceStatePerClass,
		MetadataBuildingContext context) {
	if ( elementsToProcess.getIdPropertyCount() == 1 ) {
		final PropertyData idPropertyOnBaseClass = getUniqueIdPropertyFromBaseClass(
				inferredData,
				baseInferredData,
				propertyAccessor,
				context
		);
		final InheritanceState state = inheritanceStatePerClass.get( idPropertyOnBaseClass.getClassOrElement() );
		if ( state == null ) {
			return false; //while it is likely a user error, let's consider it is something that might happen
		}
		final XClass associatedClassWithIdClass = state.getClassWithIdClass( true );
		if ( associatedClassWithIdClass == null ) {
			//we cannot know for sure here unless we try and find the @EmbeddedId
			//Let's not do this thorough checking but do some extra validation
			final XProperty property = idPropertyOnBaseClass.getProperty();
			return property.isAnnotationPresent( ManyToOne.class )
					|| property.isAnnotationPresent( OneToOne.class );

		}
		else {
			final XClass idClass = context.getBootstrapContext().getReflectionManager().toXClass(
					associatedClassWithIdClass.getAnnotation( IdClass.class ).value()
			);
			return idClass.equals( compositeClass );
		}
	}
	else {
		return false;
	}
}
 
源代码15 项目: lams   文件: PersistentAttributesHelper.java
public static CtClass getTargetEntityClass(CtClass managedCtClass, CtField persistentField) throws NotFoundException {
	// get targetEntity defined in the annotation
	try {
		OneToOne oto = PersistentAttributesHelper.getAnnotation( persistentField, OneToOne.class );
		OneToMany otm = PersistentAttributesHelper.getAnnotation( persistentField, OneToMany.class );
		ManyToOne mto = PersistentAttributesHelper.getAnnotation( persistentField, ManyToOne.class );
		ManyToMany mtm = PersistentAttributesHelper.getAnnotation( persistentField, ManyToMany.class );

		Class<?> targetClass = null;
		if ( oto != null ) {
			targetClass = oto.targetEntity();
		}
		if ( otm != null ) {
			targetClass = otm.targetEntity();
		}
		if ( mto != null ) {
			targetClass = mto.targetEntity();
		}
		if ( mtm != null ) {
			targetClass = mtm.targetEntity();
		}

		if ( targetClass != null && targetClass != void.class ) {
			return managedCtClass.getClassPool().get( targetClass.getName() );
		}
	}
	catch (NotFoundException ignore) {
	}

	// infer targetEntity from generic type signature
	String inferredTypeName = inferTypeName( managedCtClass, persistentField.getName() );
	return inferredTypeName == null ? null : managedCtClass.getClassPool().get( inferredTypeName );
}
 
源代码16 项目: oval   文件: JPAAnnotationsConfigurer.java
protected void addAssertValidCheckIfRequired(final Annotation constraintAnnotation, final Collection<Check> checks,
   @SuppressWarnings("unused") /*parameter for potential use by subclasses*/final AccessibleObject fieldOrMethod) {
   if (containsCheckOfType(checks, AssertValidCheck.class))
      return;

   if (constraintAnnotation instanceof OneToOne || constraintAnnotation instanceof OneToMany || constraintAnnotation instanceof ManyToOne
      || constraintAnnotation instanceof ManyToMany) {
      checks.add(new AssertValidCheck());
   }
}
 
源代码17 项目: we-cmdb   文件: AdmIntegrateTemplateAlias.java
@OneToOne(mappedBy = "childIntegrateTemplateAlias")
public AdmIntegrateTemplateRelation getParentIntegrateTemplateRelation() {
    return this.parentIntegrateTemplateRelation;
}
 
源代码18 项目: youkefu   文件: DataEvent.java
@OneToOne
   @JoinColumn(name="creater",insertable=false , updatable = false,unique=false)  
public User getUser() {
	return user;
}
 
源代码19 项目: youkefu   文件: RecentUser.java
@OneToOne
public User getUser() {
	return user;
}
 
源代码20 项目: youkefu   文件: OrganRole.java
@OneToOne(optional = true)
public Organ getOrgan() {
	return organ;
}
 
源代码21 项目: youkefu   文件: IMGroupUser.java
@OneToOne
public IMGroup getImgroup() {
	return imgroup;
}
 
源代码22 项目: SeaCloudsPlatform   文件: GuaranteeTerm.java
@Override
@OneToOne(targetEntity = BusinessValueList.class, cascade = CascadeType.ALL)
@JoinColumn(name = "business_value_id")
public IBusinessValueList getBusinessValueList() {
    return businessValueList;
}
 
源代码23 项目: youkefu   文件: UserRole.java
@OneToOne(optional = true)
public Role getRole() {
	return role;
}
 
源代码24 项目: TinyMooc   文件: Resource.java
@OneToOne(fetch = FetchType.LAZY, mappedBy = "resource")
public ImageText getImageText() {
    return this.imageText;
}
 
源代码25 项目: Exam-Online   文件: SysModifyLog.java
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "creator_user_id", updatable = false)
public SysUser getCreator() {
	return creator;
}
 
源代码26 项目: Exam-Online   文件: SysModifyLog.java
@OneToOne(fetch=FetchType.LAZY)
@JoinColumn(name = "modifier_user_id")
public SysUser getModifier() {
	return modifier;
}
 
源代码27 项目: TinyMooc   文件: Resource.java
@OneToOne(fetch = FetchType.LAZY, mappedBy = "resource")
public Link getLink() {
    return this.link;
}
 
源代码28 项目: ignite   文件: HibernateL2CacheSelfTest.java
/**
 * @return Referenced entity.
 */
@OneToOne
public Entity getEntity() {
    return entity;
}
 
源代码29 项目: celerio-angular-quickstart   文件: User.java
@OneToOne(mappedBy = "holder")
public Passport getPassport() {
    return passport;
}
 
源代码30 项目: minnal   文件: OneToOneAnnotationHandlerTest.java
@BeforeMethod
public void setup() {
	handler = new OneToOneAnnotationHandler();
	annotation = mock(OneToOne.class);
	metaData = mock(EntityMetaData.class);
}
 
 类所在包
 同包方法