下面列出了javax.persistence.OneToOne#mappedBy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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 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;
}
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;
}