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(); }
ad.setValue( "fetch", oneToOne.fetch() ); ad.setValue( "optional", oneToOne.optional() ); ad.setValue( "mappedBy", oneToOne.mappedBy() ); ad.setValue( "orphanRemoval", oneToOne.orphanRemoval() );
OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class ); String mappedBy = oneToOneAnn != null ? oneToOneAnn.mappedBy() : null; joinColumns = Ejb3JoinColumn.buildJoinColumns(
Arrays.asList(oneToOneAnn.cascade()), oneToOneAnn.optional(), oneToOneAnn.mappedBy(), Relation.ForeignKey.ONE_TO_ONE);
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) { prop.setOneToOne(); prop.setDbInsertable(true); prop.setDbUpdateable(true); prop.setNullable(propAnn.optional()); prop.setFetchType(propAnn.fetch()); prop.setMappedBy(propAnn.mappedBy()); if (!"".equals(propAnn.mappedBy())) { prop.setOneToOneExported(); prop.setOrphanRemoval(propAnn.orphanRemoval()); } else if (propAnn.orphanRemoval()) { prop.setOrphanRemoval(true); } setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo()); prop.setBeanTable(beanTable(prop)); }
/** * INTERNAL: (Overridden in XMLOneToOneAccessor) */ public String getMappedBy() { return (m_oneToOne == null) ? "" : m_oneToOne.mappedBy(); }
@Override protected String getMappedBy(Field field) { return field.getAnnotation(OneToOne.class).mappedBy(); } @Override
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; }
propertyHolder, inferredData, ann.mappedBy(), trueOneToOne, isIdentifierMapper,
public static boolean isPersistentGetterOwnerOfRelation(Method getter) { if (getter.isAnnotationPresent(ManyToOne.class)) return true; if (getter.isAnnotationPresent(Embeddable.class)) return true; OneToMany ann = getter.getAnnotation(OneToMany.class); if (ann != null && ann.mappedBy() != null) return false; OneToOne annO = getter.getAnnotation(OneToOne.class); if (annO != null && StringUtils.isEmpty(annO.mappedBy())) return true; throw new RuntimeException("isPersistentGetterOwnerOfRelation("+getter+")? don't konw"); }
public static String getMappedName(Field field) { if (field.isAnnotationPresent(OneToOne.class)) { OneToOne one = field.getAnnotation(OneToOne.class); if (!one.mappedBy().trim().equals("")) { return one.mappedBy(); } } if (field.isAnnotationPresent(OneToMany.class)) { OneToMany one = field.getAnnotation(OneToMany.class); if (!one.mappedBy().trim().equals("")) { return one.mappedBy(); } } return null; }
public static boolean isOneToOneAndMappedBy(Class<?> classMaster, EntityType<?> entiyType) { for (Field field : entiyType.getJavaType().getDeclaredFields()) { if (!ReflectionUtils.getGenericClass(field).equals(classMaster)) { continue; } OneToOne oneToOne = field.getAnnotation(OneToOne.class); if (oneToOne == null) { continue; } LogUtils.warning("Field = " + field.getName() + " / " + field.getType() + " tem mappedBy " + !oneToOne.mappedBy().isEmpty()); return !oneToOne.mappedBy().isEmpty(); } return false; }
public static boolean isOneToOneAndMappedBy(Class<?> classMaster, EntityType<?> entiyType) { for (Field field : entiyType.getJavaType().getDeclaredFields()) { if (!ReflectionUtils.getGenericClass(field).equals(classMaster)) { continue; } OneToOne oneToOne = field.getAnnotation(OneToOne.class); if (oneToOne == null) { continue; } LogUtils.warning("Field = " + field.getName() + " / " + field.getType() + " tem mappedBy " + !oneToOne.mappedBy().isEmpty()); return !oneToOne.mappedBy().isEmpty(); } return false; }
protected String getInverseField(Field field) { OneToMany oneToManyAnnotation = field.getAnnotation(OneToMany.class); if (oneToManyAnnotation != null) return isBlank(oneToManyAnnotation.mappedBy()) ? null : oneToManyAnnotation.mappedBy(); ManyToMany manyToManyAnnotation = field.getAnnotation(ManyToMany.class); if (manyToManyAnnotation != null) return isBlank(manyToManyAnnotation.mappedBy()) ? null : manyToManyAnnotation.mappedBy(); OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); if (oneToOneAnnotation != null) return isBlank(oneToOneAnnotation.mappedBy()) ? null : oneToOneAnnotation.mappedBy(); return null; }
boolean isMapped() { if (jpaAttribute.getPersistentAttributeType() == PersistentAttributeType.ONE_TO_ONE) { final AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember(); final OneToOne cardinalityOtO = annotatedElement.getAnnotation(OneToOne.class); return cardinalityOtO.mappedBy() != null && !cardinalityOtO.mappedBy().isEmpty() ? true : false; } if (jpaAttribute.getPersistentAttributeType() == PersistentAttributeType.ONE_TO_MANY) { final AnnotatedElement annotatedElement = (AnnotatedElement) jpaAttribute.getJavaMember(); final OneToMany cardinalityOtM = annotatedElement.getAnnotation(OneToMany.class); return cardinalityOtM.mappedBy() != null && !cardinalityOtM.mappedBy().isEmpty() ? true : false; } return false; }
private void introspectOneToOne(OneToOne oneToOne) { Class targetClass = oneToOne.targetEntity(); if (void.class.equals(targetClass)) targetClass = _fieldType; setTargetEntity(targetClass); setCascadeTypes(oneToOne.cascade()); setFetch(oneToOne.fetch()); _isOptional = oneToOne.optional(); _mappedBy = oneToOne.mappedBy(); }
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(); }
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) { prop.setOneToOne(); prop.setDbInsertable(true); prop.setDbUpdateable(true); prop.setNullable(propAnn.optional()); prop.setFetchType(propAnn.fetch()); prop.setMappedBy(propAnn.mappedBy()); if (!"".equals(propAnn.mappedBy())) { prop.setOneToOneExported(); } setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo()); BeanTable assoc = factory.getBeanTable(prop.getPropertyType()); if (assoc == null) { String msg = errorMsgMissingBeanTable(prop.getPropertyType(), prop.getFullBeanName()); throw new RuntimeException(msg); } prop.setBeanTable(assoc); }
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) { prop.setOneToOne(true); prop.setDbInsertable(true); prop.setDbUpdateable(true); prop.setNullable(propAnn.optional()); prop.setFetchType(propAnn.fetch()); prop.setMappedBy(propAnn.mappedBy()); if (!"".equals(propAnn.mappedBy())) { prop.setOneToOneExported(true); } setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo()); BeanTable assoc = factory.getBeanTable(prop.getPropertyType()); if (assoc == null) { String msg = errorMsgMissingBeanTable(prop.getPropertyType(), prop.getFullBeanName()); throw new RuntimeException(msg); } prop.setBeanTable(assoc); }
private void readOneToOne(OneToOne propAnn, DeployBeanPropertyAssocOne<?> prop) { prop.setOneToOne(); prop.setDbInsertable(true); prop.setDbUpdateable(true); prop.setNullable(propAnn.optional()); prop.setFetchType(propAnn.fetch()); prop.setMappedBy(propAnn.mappedBy()); if (!"".equals(propAnn.mappedBy())) { prop.setOneToOneExported(); prop.setOrphanRemoval(propAnn.orphanRemoval()); } else if (propAnn.orphanRemoval()) { prop.setOrphanRemoval(true); } setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo()); prop.setBeanTable(beanTable(prop)); }