Java 类javax.persistence.Embedded 实例源码

项目:invesdwin-context-persistence    文件:ACustomIdDao.java   
private boolean determineDeleteInBatchSupported(final Class<?> genericType) {
    final MutableBoolean deleteInBatchSupported = new MutableBoolean(true);
    Reflections.doWithFields(genericType, new FieldCallback() {
        @Override
        public void doWith(final Field field) {
            if (!deleteInBatchSupported.getValue()) {
                return;
            } else if (Reflections.getAnnotation(field, ElementCollection.class) != null) {
                //element collections are mapped as separate tables, thus the values would cause a foreign key constraint violation
                deleteInBatchSupported.setValue(false);
            } else if (Reflections.getAnnotation(field, Embedded.class) != null) {
                //check embedded types for the same constraints
                if (!determineDeleteInBatchSupported(field.getType())) {
                    deleteInBatchSupported.setValue(false);
                }
            }
        }
    });
    return deleteInBatchSupported.getValue();
}
项目:metaworks_framework    文件:AdminAuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:metaworks_framework    文件:AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:metaworks_framework    文件:AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:metaworks_framework    文件:AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:SparkCommerce    文件:AdminAuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:SparkCommerce    文件:AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:SparkCommerce    文件:AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:SparkCommerce    文件:AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:blcdemo    文件:AdminAuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), getAuditableFieldName());
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalCreatedField = auditable.getClass().getDeclaredField("dateCreated");
            Field temporalUpdatedField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalCreatedField, auditable);
            setAuditValueTemporal(temporalUpdatedField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:blcdemo    文件:AdminAuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), getAuditableFieldName());
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new AdminAuditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:blcdemo    文件:AuditableListener.java   
@PrePersist
public void setAuditCreatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateCreated");
            Field agentField = auditable.getClass().getDeclaredField("createdBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:blcdemo    文件:AuditableListener.java   
@PreUpdate
public void setAuditUpdatedBy(Object entity) throws Exception {
    if (entity.getClass().isAnnotationPresent(Entity.class)) {
        Field field = getSingleField(entity.getClass(), "auditable");
        field.setAccessible(true);
        if (field.isAnnotationPresent(Embedded.class)) {
            Object auditable = field.get(entity);
            if (auditable == null) {
                field.set(entity, new Auditable());
                auditable = field.get(entity);
            }
            Field temporalField = auditable.getClass().getDeclaredField("dateUpdated");
            Field agentField = auditable.getClass().getDeclaredField("updatedBy");
            setAuditValueTemporal(temporalField, auditable);
            setAuditValueAgent(agentField, auditable);
        }
    }
}
项目:org.fastnate    文件:EntityClass.java   
/**
 * Builds the property for the given attribute.
 *
 * @param attribute
 *            the attribute to inspect
 * @param columnMetadata
 *            the attached (or overriden) column metadata
 * @param override
 *            the AssociationOverride found for this attribute
 * @return the property that represents the attribute or {@code null} if not persistent
 */
<X> Property<X, ?> buildProperty(final AttributeAccessor attribute, final Column columnMetadata,
        final AssociationOverride override) {
    if (attribute.isPersistent()) {
        if (CollectionProperty.isCollectionProperty(attribute)) {
            return new CollectionProperty<>(this, attribute, override);
        } else if (MapProperty.isMapProperty(attribute)) {
            return new MapProperty<>(this, attribute, override);
        } else if (EntityProperty.isEntityProperty(attribute)) {
            return new EntityProperty<>(this.context, getTable(), attribute, override);
        } else if (attribute.isAnnotationPresent(Embedded.class)) {
            return new EmbeddedProperty<>(this, attribute);
        } else if (attribute.isAnnotationPresent(Version.class)) {
            return new VersionProperty<>(this.context, this.table, attribute, columnMetadata);
        } else {
            return new PrimitiveProperty<>(this.context, this.table, attribute, columnMetadata);
        }
    }
    return null;
}
项目:easyjweb    文件:AllProcessor.java   
@SuppressWarnings("unchecked")
private void resovleEmbed(List<Map> fields, List<Map> complexFields,
        Field field) {
    if (field.isAnnotationPresent(Embedded.class)) {
        for (Field f : field.getType().getDeclaredFields()) {
            if ((field.getName().equals("status"))
                    || field.getName().equals("serialVersionUID")) {
                continue;
            }
            if (resovleGenerAnno(field)) {
                continue;
            }
            if (isSimpleType(f.getType())) {
                fields.add(parseField(f));
            }
        }
        complexFields.remove(complexFields.size() - 1);
    }
}
项目:cosmic    文件:DbUtil.java   
public static Field findField(final Class<?> clazz, final String columnName) {
    for (final Field field : clazz.getDeclaredFields()) {
        if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
            findField(field.getClass(), columnName);
        } else {
            if (columnName.equals(DbUtil.getColumnName(field))) {
                return field;
            }
        }
    }
    return null;
}
项目:metaworks_framework    文件:TemporalTimestampListener.java   
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
项目:alex    文件:Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "duration_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "duration_eqOracle"))
})
public DetailedStatistics getDuration() {
    return duration;
}
项目:alex    文件:Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "mqs_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "mqs_eqOracle"))
})
public DetailedStatistics getMqsUsed() {
    return mqsUsed;
}
项目:alex    文件:Statistics.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name = "learner", column = @Column(name = "symbolsUsed_learner")),
        @AttributeOverride(name = "eqOracle", column = @Column(name = "symbolsUsed_eqOracle"))
})
public DetailedStatistics getSymbolsUsed() {
    return symbolsUsed;
}
项目:SparkCommerce    文件:TemporalTimestampListener.java   
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
项目:amos-ss15-proj2    文件:SuperTripSubQuery.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name= RouteLocation.COLUMN_LAT, column = @Column(name = "sLat")),
        @AttributeOverride(name= RouteLocation.COLUMN_LNG, column = @Column(name = "sLng"))
})
public RouteLocation getStartLocation() {
    return startLocation;
}
项目:amos-ss15-proj2    文件:SuperTripSubQuery.java   
@Embedded
@AttributeOverrides({
        @AttributeOverride(name= RouteLocation.COLUMN_LAT, column = @Column(name = "eLat")),
        @AttributeOverride(name= RouteLocation.COLUMN_LNG, column = @Column(name = "eLng"))
})
public RouteLocation getDestinationLocation() {
    return destinationLocation;
}
项目:blcdemo    文件:TemporalTimestampListener.java   
private void setTimestamps(Field[] fields, Object entity) throws Exception {
    Calendar cal = null;
    for (Field field : fields) {
        Class<?> type = field.getType();
        Temporal temporalAnnotation = field.getAnnotation(Temporal.class);

        if (temporalAnnotation != null) {
            if (field.isAnnotationPresent(Column.class)) {
                field.setAccessible(true);
                try {
                    if (TemporalType.TIMESTAMP.equals(temporalAnnotation.value()) && (field.isAnnotationPresent(AutoPopulate.class))) {
                        if (field.get(entity) == null || field.getAnnotation(AutoPopulate.class).autoUpdateValue()) {
                            if (type.isAssignableFrom(Date.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal.getTime());
                            } else if (type.isAssignableFrom(Calendar.class)) {
                                if (cal == null) {
                                    cal = SystemTime.asCalendar();
                                }
                                field.set(entity, cal);
                            }
                        }
                    }
                } finally {
                    field.setAccessible(false);
                }
            }
        } else if (field.isAnnotationPresent(Embedded.class)) {
            field.setAccessible(true);
            try {
                // Call recursively
                setTimestamps(field.getType().getDeclaredFields(), field.get(entity));
            } finally {
                field.setAccessible(false);
            }
        }
    }
}
项目:petit    文件:BeanMappingUtils.java   
/**
 * Adds an extended property to the BeanMapping. 
 * 
 * @param props
 * @param name
 * @param type
 * @param columnMapping
 * @return
 */
public static <B> Property<B, Object> initExtendedProperty(Map<String, Property<B, Object>> props, String name, Class<B> type, String columnMapping) {
    PropertyDescriptor pd = BeanMappingReflectionUtils.getPropertyDescriptor(type, name);

    if (!isPropertyReadableAndWritable(pd)) {
        return null;
    }

    List<Annotation> ans = BeanMappingReflectionUtils.readAnnotations(type, pd.getName());

    Column column = BeanMappingReflectionUtils.getAnnotation(ans, Column.class);

    ReflectionProperty<B, Object> prop = new ReflectionProperty<B, Object>(name,
            (Class<Object>) pd.getPropertyType(), inferColumn(columnMapping != null ? columnMapping : name, column), pd.getWriteMethod(),
            pd.getReadMethod());

    if (column != null) {
        prop.readOnly(true);
    }

    if (BeanMappingReflectionUtils.getAnnotation(ans, Id.class) != null) {
        prop.setIdProperty(true);
    }

    if (useAdditionalConfiguration()) {
        prop.getConfiguration().setAnnotations(ans);
        if (Collection.class.isAssignableFrom(pd.getPropertyType())) {
            prop.getConfiguration().setCollectionTypeArguments(
                    ((ParameterizedType) pd.getReadMethod().getGenericReturnType()).getActualTypeArguments());
        }
    }

    if (BeanMappingReflectionUtils.getAnnotation(ans, Embedded.class) != null) {
        props.putAll(getCompositeProperties(prop, ans));
    } else {
        props.put(prop.name(), prop);
    }

    return prop;
}
项目:cloudstack    文件:DbUtil.java   
public static Field findField(Class<?> clazz, String columnName) {
    for (Field field : clazz.getDeclaredFields()) {
        if (field.getAnnotation(Embedded.class) != null || field.getAnnotation(EmbeddedId.class) != null) {
            findField(field.getClass(), columnName);
        } else {
            if (columnName.equals(DbUtil.getColumnName(field))) {
                return field;
            }
        }
    }
    return null;
}
项目:hsw    文件:Veranstaltungsort.java   
@Embedded
@AttributeOverrides( {
        @AttributeOverride(name = "breite", column = @Column(name = "GEO_BREITE")),
        @AttributeOverride(name = "laenge", column = @Column(name = "GEO_LAENGE")) })
public GeoKoordinaten getKoordinaten() {
    return koordinaten;
}
项目:zekke-webapp    文件:Place.java   
@Embedded
@AttributeOverrides({
    @AttributeOverride(name = "latitude", column = @Column(name = "latitude", nullable = false, precision = 22, scale = 0)),
    @AttributeOverride(name = "longitude", column = @Column(name = "longitude", nullable = false, precision = 22, scale = 0))
})
public GeoPoint getPosition() {
    return position;
}
项目:carcv    文件:FileEntry.java   
/**
 * @return CarData of this FileEntry
 */
@Override
@NotNull
@Embedded
public CarData getCarData() {
    return carData;
}
项目:lams    文件:Enhancer.java   
private CtMethod generateFieldWriter(
        CtClass managedCtClass,
        CtField persistentField,
        AttributeTypeDescriptor typeDescriptor) {

    final FieldInfo fieldInfo = persistentField.getFieldInfo();
    final String fieldName = fieldInfo.getName();
    final String writerName = EnhancerConstants.PERSISTENT_FIELD_WRITER_PREFIX + fieldName;

    final CtMethod writer;

    try {
        if ( !enhancementContext.isLazyLoadable( persistentField ) ) {
            // not lazy-loadable...
            writer = CtNewMethod.setter( writerName, persistentField );
        }
        else {
            final String methodBody = typeDescriptor.buildWriteInterceptionBodyFragment( fieldName );
            writer = CtNewMethod.make(
                    Modifier.PRIVATE,
                    CtClass.voidType,
                    writerName,
                    new CtClass[] {persistentField.getType()},
                    null,
                    "{" + methodBody + "}",
                    managedCtClass
            );
        }

        if ( enhancementContext.doDirtyCheckingInline( managedCtClass ) && !isComposite ) {
            writer.insertBefore( typeDescriptor.buildInLineDirtyCheckingBodyFragment( persistentField ) );
        }

        if ( isComposite ) {
            StringBuilder builder = new StringBuilder();
            builder.append( " if(  " )
                    .append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
                    .append( " != null) " )
                    .append( EnhancerConstants.TRACKER_COMPOSITE_FIELD_NAME )
                    .append( ".callOwner(\"." )
                    .append( persistentField.getName() )
                    .append( "\");" );

            writer.insertBefore( builder.toString() );
        }

        //composite types
        if ( persistentField.getAnnotation( Embedded.class ) != null ) {
            //make sure to add the CompositeOwner interface
            if ( !doClassInheritCompositeOwner( managedCtClass ) ) {
                managedCtClass.addInterface( classPool.get( "org.hibernate.engine.spi.CompositeOwner" ) );
            }
            //if a composite have a embedded field we need to implement the method as well
            if ( isComposite ) {
                createTrackChangeCompositeMethod( managedCtClass );
            }


            writer.insertBefore( cleanupPreviousOwner( persistentField ) );

            writer.insertAfter( compositeMethodBody( persistentField ) );
        }

        managedCtClass.addMethod( writer );
        return writer;
    }
    catch (Exception e) {
        throw new EnhancementException(
                String.format(
                        "Could not enhance entity class [%s] to add field writer method [%s]",
                        managedCtClass.getName(),
                        writerName
                ),
                e
        );
    }
}
项目:Hibernate_Component_Mapping_Using_DAO_Using_Maven    文件:person.java   
@Embedded
public Jobs getJob() {
    return job;
}
项目:webpedidos    文件:Pedido.java   
@Embedded
public EnderecoEntrega getEnderecoEntrega() {
    return this.enderecoEntrega;
}
项目:oma-riista-web    文件:JpaModelTest.java   
@Test
public void nullableConstraintsMustBeMutuallyConsistent() {
    final Stream<Field> failedFields = filterFieldsOfManagedJpaTypes(field -> {
        if (field.isAnnotationPresent(Version.class) || field.isAnnotationPresent(ElementCollection.class)) {
            return false;
        }

        final boolean isPrimitive = field.getType().isPrimitive();

        final boolean notNull = field.isAnnotationPresent(NotNull.class);
        final boolean notEmpty = field.isAnnotationPresent(NotEmpty.class);
        final boolean notBlank = field.isAnnotationPresent(NotBlank.class);

        final boolean notNullOrEmpty = notNull || notEmpty || notBlank;

        final boolean embedded = field.isAnnotationPresent(Embedded.class);

        final Column column = field.getAnnotation(Column.class);
        final ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);
        final OneToOne oneToOne = field.getAnnotation(OneToOne.class);
        final JoinColumn joinColumn = field.getAnnotation(JoinColumn.class);

        if (column != null) {
            if (manyToOne != null && column.nullable() != manyToOne.optional() ||
                    oneToOne != null && column.nullable() != oneToOne.optional() ||
                    joinColumn != null && column.nullable() != joinColumn.nullable() ||
                    column.nullable() && (notNullOrEmpty || isPrimitive) ||
                    !isPrimitive && column.insertable() && !column.nullable() && !notNullOrEmpty) {

                return true;
            }
        }
        if (joinColumn != null) {
            if (manyToOne != null && joinColumn.nullable() != manyToOne.optional() ||
                    oneToOne != null && joinColumn.nullable() != oneToOne.optional() ||
                    joinColumn.nullable() && notNull ||
                    joinColumn.insertable() && !joinColumn.nullable() && !notNull) {

                return true;
            }
        }
        if (manyToOne != null) {
            if (!isIdField(field) && manyToOne.optional() == notNull) {
                return true;
            }
        }
        if (oneToOne != null) {
            if (!isIdField(field) && oneToOne.optional() == notNull) {
                return true;
            }
        }
        if (notNullOrEmpty && !embedded) {
            if (column == null && joinColumn == null && manyToOne == null && oneToOne == null) {
                return true;
            }
        }

        return false;
    });

    assertNoFields(failedFields,
            "Entity fields should have consistency with regard to:\n" +
                    "    (1) Presence of @NotNull, @NotBlank or @NotEmpty\n" +
                    "    (2) Values of @Column.nullable, @ManyToOne.optional, @OneToOne.optional and " +
                    "@JoinColumn.nullable\n" +
                    "    (3) Whether the type of field is primitive or not\n" +
                    "  These fields fail: ");
}