Java 类javax.persistence.OneToOne 实例源码

项目:Equella    文件:Property.java   
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;
}
项目:crnk-framework    文件:JpaMetaFilter.java   
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;
}
项目:crnk-framework    文件:JpaResourceFieldInformationProvider.java   
@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();
}
项目: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;
    }
项目:oma-riista-web    文件:JpaModelTest.java   
/**
 * 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: ");
}
项目:infiniquery-core    文件:DefaultQueryModelService.java   
/**
 * 
 * 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());
    }
}
项目:katharsis-framework    文件:AbstractEntityMetaProvider.java   
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;
}
项目:infiniquery-core    文件:DefaultQueryModelService.java   
/**
 * 
 * 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());
    }
}
项目:blcdemo    文件:MapFieldPersistenceProvider.java   
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;
}
项目:hql-builder    文件:EntityRelationHelper.java   
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;
}
项目:hql-builder    文件:EntityRelationHelper.java   
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;
}
项目:hql-builder    文件:EntityRelationHelper.java   
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;
}
项目:karaku    文件:BaseDAOImpl.java   
/**
 * 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;
}
项目:org.fastnate    文件:EntityClass.java   
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);
            }
        }
    }
}
项目:jbromo    文件:EntityUtil.java   
/**
 * 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;
}
项目:further-open-core    文件:JpaAnnotationUtil.java   
/**
 * @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;
}
项目:bjug-querydsl    文件:JpaEntityResourceMetadataExtractor.java   
/**
 * 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);
    }
}
项目:sneo    文件:Vlan.java   
@OneToOne(
  fetch = FetchType.LAZY,
  orphanRemoval = true,
  cascade = {
    CascadeType.REMOVE
  },
  optional = false
)
@JoinColumn(
  name = "IP_ADDRESS_RELATION_ID",
  nullable = false,
  unique = true
)
public VlanIpAddressRelation getIpAddressRelation() {
  return ipAddressRelation;
}
项目:sneo    文件:RealNetworkInterfaceConfiguration.java   
@OneToOne(
  fetch = FetchType.LAZY,
  orphanRemoval = true,
  cascade = {
    CascadeType.REMOVE
  },
  optional = false
)
@JoinColumn(
  name = "IP_ADDRESS_RELATION_ID",
  nullable = false,
  unique = true
)
public RealNetworkInterfaceConfigurationIpAddressRelation
getIpAddressRelation() {
  return ipAddressRelation;
}
项目:oscm    文件:ReflectiveClone.java   
private static boolean needsToCascade(Field field) {
    Class<?> fieldtype = field.getType();
    if (!DomainObject.class.isAssignableFrom(fieldtype))
        return false;
    Annotation ann;
    CascadeType[] cascades = null;
    ann = field.getAnnotation(OneToOne.class);
    if (ann != null) {
        cascades = ((OneToOne) ann).cascade();
    } else {
        ann = field.getAnnotation(OneToMany.class);
        if (ann != null) {
            cascades = ((OneToMany) ann).cascade();
        } else {
            ann = field.getAnnotation(ManyToOne.class);
            if (ann != null) {
                cascades = ((ManyToOne) ann).cascade();
            } else {
                ann = field.getAnnotation(ManyToMany.class);
                if (ann != null) {
                    cascades = ((ManyToMany) ann).cascade();
                }
            }
        }
    }
    if (cascades == null)
        return false;
    for (CascadeType cas : cascades) {
        if ((cas == CascadeType.ALL) || (cas == CascadeType.MERGE)
                || (cas == CascadeType.PERSIST)
                || (cas == CascadeType.REMOVE)) {
            return true;
        }
    }
    return false;
}
项目:lams    文件:PropertyContainer.java   
private static boolean discoverTypeWithoutReflection(XProperty p) {
    if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class )
            .targetEntity()
            .equals( void.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( OneToMany.class ) && !p.getAnnotation( OneToMany.class )
            .targetEntity()
            .equals( void.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( ManyToOne.class ) && !p.getAnnotation( ManyToOne.class )
            .targetEntity()
            .equals( void.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( ManyToMany.class ) && !p.getAnnotation( ManyToMany.class )
            .targetEntity()
            .equals( void.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( org.hibernate.annotations.Any.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( ManyToAny.class ) ) {
        if ( !p.isCollection() && !p.isArray() ) {
            throw new AnnotationException( "@ManyToAny used on a non collection non array property: " + p.getName() );
        }
        return true;
    }
    else if ( p.isAnnotationPresent( Type.class ) ) {
        return true;
    }
    else if ( p.isAnnotationPresent( Target.class ) ) {
        return true;
    }
    return false;
}
项目: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(), mappings
        );
        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(), mappings
        );
    }
    return joinColumns;
}
项目: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() );
}
项目:lams    文件:AnnotationBinder.java   
private static boolean isIdClassPkOfTheAssociatedEntity(
        InheritanceState.ElementsToProcess elementsToProcess,
        XClass compositeClass,
        PropertyData inferredData,
        PropertyData baseInferredData,
        AccessType propertyAccessor,
        Map<XClass, InheritanceState> inheritanceStatePerClass,
        Mappings mappings) {
    if ( elementsToProcess.getIdPropertyCount() == 1 ) {
        final PropertyData idPropertyOnBaseClass = getUniqueIdPropertyFromBaseClass(
                inferredData, baseInferredData, propertyAccessor, mappings
        );
        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 = mappings.getReflectionManager().toXClass(
                    associatedClassWithIdClass.getAnnotation( IdClass.class ).value()
            );
            return idClass.equals( compositeClass );
        }
    }
    else {
        return false;
    }
}
项目:uckefu    文件:TopicComment.java   
@OneToOne(cascade  =  CascadeType.PERSIST)
   @JoinColumns ({
       @JoinColumn(name  =   "view" , referencedColumnName  =   "dataid" ),
       @JoinColumn(name  =   "creater" , referencedColumnName  =   "creater" )
   })
public TopicView getView() {
    return view;
}
项目:oasp-tutorial-sources    文件:VisitorEntity.java   
/**
 * @return code
 */
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "idCode")
public AccessCodeEntity getCode() {

  return this.code;
}
项目:oasp-tutorial-sources    文件:AccessCodeEntity.java   
/**
 * @return visitor
 */
@OneToOne
@JoinColumn(name = "idVisitor")
public VisitorEntity getVisitor() {

  return this.visitor;
}
项目:oma-riista-web    文件:JpaModelTest.java   
/**
 * To differentiate @OneToOne associations from @ManyToOne ones.
 */
@Test
public void nonInverseOneToOneAssociationsMustHaveUniqueJoinColumn() {
    final Stream<Field> failedFields = filterFieldsOfManagedJpaTypes(field -> {
        final OneToOne oneToOne = field.getAnnotation(OneToOne.class);
        final JoinColumn joinCol = field.getAnnotation(JoinColumn.class);

        return !isIdField(field) && oneToOne != null && "".equals(oneToOne.mappedBy()) &&
                (joinCol == null || !joinCol.unique());
    });

    assertNoFields(failedFields, "These entity fields should be annotated with @JoinColumn(unique = true): ");
}
项目:katharsis-framework    文件:AbstractEntityMetaProvider.java   
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;
}
项目:domui    文件:HibernateChecker.java   
private void checkOneToOne(Method g) {
    OneToOne annotation = g.getAnnotation(OneToOne.class);
    if(null == annotation)
        return;
    if(annotation.optional() && annotation.fetch() == FetchType.LAZY) {
        problem(Severity.ERROR, "@OneOnOne that is optional with fetch=LAZY does eager fetching, causing big performance trouble");
        m_badOneToOne++;
    }
}
项目:cuba    文件:EntityInspectorEditor.java   
protected boolean isRequired(MetaProperty metaProperty) {
    if (metaProperty.isMandatory())
        return true;

    ManyToOne many2One = metaProperty.getAnnotatedElement().getAnnotation(ManyToOne.class);
    if (many2One != null && !many2One.optional())
        return true;

    OneToOne one2one = metaProperty.getAnnotatedElement().getAnnotation(OneToOne.class);
    return one2one != null && !one2one.optional();
}
项目:development    文件:ReflectiveClone.java   
private static boolean needsToCascade(Field field) {
    Class<?> fieldtype = field.getType();
    if (!DomainObject.class.isAssignableFrom(fieldtype))
        return false;
    Annotation ann;
    CascadeType[] cascades = null;
    ann = field.getAnnotation(OneToOne.class);
    if (ann != null) {
        cascades = ((OneToOne) ann).cascade();
    } else {
        ann = field.getAnnotation(OneToMany.class);
        if (ann != null) {
            cascades = ((OneToMany) ann).cascade();
        } else {
            ann = field.getAnnotation(ManyToOne.class);
            if (ann != null) {
                cascades = ((ManyToOne) ann).cascade();
            } else {
                ann = field.getAnnotation(ManyToMany.class);
                if (ann != null) {
                    cascades = ((ManyToMany) ann).cascade();
                }
            }
        }
    }
    if (cascades == null)
        return false;
    for (CascadeType cas : cascades) {
        if ((cas == CascadeType.ALL) || (cas == CascadeType.MERGE)
                || (cas == CascadeType.PERSIST)
                || (cas == CascadeType.REMOVE)) {
            return true;
        }
    }
    return false;
}
项目:opencucina    文件:HistoryRecord.java   
/**
 * JAVADOC Method Level Comments
 *
 * @return JAVADOC.
 */

//@Transient
@OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "attachment")
public Attachment getAttachment() {
    return attachment;
}
项目: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());
}
项目: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;
}
项目: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 = "SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getScript() {
    return script;
}
项目:scheduling    文件:TaskData.java   
@Cascade(CascadeType.ALL)
@OneToOne(fetch = FetchType.LAZY)
// disable foreign key, to be able to remove runtime data
@JoinColumn(name = "PRE_SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getPreScript() {
    return preScript;
}
项目:scheduling    文件:TaskData.java   
@Cascade(CascadeType.ALL)
@OneToOne(fetch = FetchType.LAZY)
// disable foreign key, to be able to remove runtime data
@JoinColumn(name = "POST_SCRIPT_ID", foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
public ScriptData getPostScript() {
    return postScript;
}
项目: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;
}
项目: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;
}