Java Code Examples for javax.persistence.OneToOne#optional()
The following examples show how to use
javax.persistence.OneToOne#optional() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityInspectorEditor.java From cuba with Apache License 2.0 | 5 votes |
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(); }
Example 2
Source File: AbstractEntityMetaFactory.java From crnk-framework with Apache License 2.0 | 4 votes |
@Override protected void initAttribute(MetaAttribute attr) { ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class); ManyToOne manyOneAnnotation = attr.getAnnotation(ManyToOne.class); OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class); OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class); Version versionAnnotation = attr.getAnnotation(Version.class); Lob lobAnnotation = attr.getAnnotation(Lob.class); Column columnAnnotation = attr.getAnnotation(Column.class); boolean idAttr = attr.getAnnotation(Id.class) != null || attr.getAnnotation(EmbeddedId.class) != null; boolean attrGenerated = attr.getAnnotation(GeneratedValue.class) != null; attr.setVersion(versionAnnotation != null); attr.setAssociation( manyManyAnnotation != null || manyOneAnnotation != null || oneManyAnnotation != null || oneOneAnnotation != null); attr.setLazy(isJpaLazy(attr.getAnnotations(), attr.isAssociation())); attr.setLob(lobAnnotation != null); attr.setFilterable(lobAnnotation == null); attr.setSortable(lobAnnotation == null); attr.setCascaded(getCascade(manyManyAnnotation, manyOneAnnotation, oneManyAnnotation, oneOneAnnotation)); if (attr.getReadMethod() == null) { throw new IllegalStateException("no getter found for " + attr.getParent().getName() + "." + attr.getName()); } Class<?> attributeType = attr.getReadMethod().getReturnType(); boolean isPrimitiveType = ClassUtils.isPrimitiveType(attributeType); boolean columnNullable = (columnAnnotation == null || columnAnnotation.nullable()) && (manyOneAnnotation == null || manyOneAnnotation.optional()) && (oneOneAnnotation == null || oneOneAnnotation.optional()); attr.setNullable(!isPrimitiveType && columnNullable); boolean hasSetter = attr.getWriteMethod() != null; attr.setInsertable(hasSetter && (columnAnnotation == null || columnAnnotation.insertable()) && !attrGenerated && versionAnnotation == null); attr.setUpdatable( hasSetter && (columnAnnotation == null || columnAnnotation.updatable()) && !idAttr && versionAnnotation == null); }
Example 3
Source File: JPAAnnotationsConfigurer.java From oval with Eclipse Public License 2.0 | 4 votes |
protected void initializeChecks(final OneToOne annotation, final Collection<Check> checks) { if (!annotation.optional() && !containsCheckOfType(checks, NotNullCheck.class)) { checks.add(new NotNullCheck()); } }