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; }
@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(); }
@Override public Optional<SerializeType> getSerializeType(BeanAttributeInformation attributeDesc) { Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class); if (oneToMany.isPresent()) { return toSerializeType(oneToMany.get().fetch()); } Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class); if (manyToOne.isPresent()) { return toSerializeType(manyToOne.get().fetch()); } Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class); if (manyToMany.isPresent()) { return toSerializeType(manyToMany.get().fetch()); } Optional<ElementCollection> elementCollection = attributeDesc.getAnnotation(ElementCollection.class); if (elementCollection.isPresent()) { return toSerializeType(elementCollection.get().fetch()); } return Optional.empty(); }
/** @return . */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "PLM_ISSUE_VERSION", joinColumns = { @JoinColumn(name = "ISSUE_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "VERSION_ID", nullable = false, updatable = false) }) public Set<PlmVersion> getPlmVersions() { return this.plmVersions; }
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; }
/** * * 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()); } }
protected FieldInfo buildFieldInfo(Field field) { FieldInfo info = new FieldInfo(); info.setName(field.getName()); info.setGenericType(field.getGenericType()); ManyToMany manyToMany = field.getAnnotation(ManyToMany.class); if (manyToMany != null) { info.setManyToManyMappedBy(manyToMany.mappedBy()); info.setManyToManyTargetEntity(manyToMany.targetEntity().getName()); } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany != null) { info.setOneToManyMappedBy(oneToMany.mappedBy()); info.setOneToManyTargetEntity(oneToMany.targetEntity().getName()); } MapKey mapKey = field.getAnnotation(MapKey.class); if (mapKey != null) { info.setMapKey(mapKey.name()); } return info; }
protected FieldInfo buildFieldInfo(Field field) { FieldInfo info = new FieldInfo(); info.setName(field.getName()); info.setGenericType(field.getGenericType()); ManyToMany manyToMany = field.getAnnotation(ManyToMany.class); if (manyToMany != null) { info.setManyToManyMappedBy(manyToMany.mappedBy()); info.setManyToManyTargetEntity(manyToMany.targetEntity().getName()); } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany != null) { info.setOneToManyMappedBy(oneToMany.mappedBy()); info.setOneToManyTargetEntity(oneToMany.targetEntity().getName()); } return info; }
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; }
@ReadPermission(expression = "allow all OR deny all") @UpdatePermission(expression = "allow all OR deny all") // Hibernate @ManyToMany( targetEntity = Child.class, cascade = { CascadeType.PERSIST, CascadeType.MERGE } ) @JoinTable( name = "Parent_Child", joinColumns = @JoinColumn(name = "parent_id"), inverseJoinColumns = @JoinColumn(name = "child_id") ) @NotNull public Set<Child> getChildren() { return children; }
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; }
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; }
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; }
@Override public Optional<String> getOppositeName(BeanAttributeInformation attributeDesc) { Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class); if (oneToMany.isPresent()) { return Optional.ofNullable(StringUtils.emptyToNull(oneToMany.get().mappedBy())); } Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class); if (manyToMany.isPresent()) { return Optional.ofNullable(StringUtils.emptyToNull(manyToMany.get().mappedBy())); } return Optional.empty(); }
public boolean isManyToMany() { if( isManyToMany == null ) { isManyToMany = getAnnotation(ManyToMany.class) != null; } return isManyToMany; }
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; }
@Override public boolean isMappedCollection(CtField field) { try { return (field.getAnnotation(OneToMany.class) != null || field.getAnnotation(ManyToMany.class) != null || field.getAnnotation(ElementCollection.class) != null); } catch (ClassNotFoundException e) { return false; } }
@XmlTransient @LazyCollection(LazyCollectionOption.EXTRA) @ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL) @JoinTable(name = "role_mappings", joinColumns = { @JoinColumn(name = "user_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "role", nullable = false, updatable = false) }) public List<Role> getRoles() {return _roles;}
@ManyToMany(fetch=FetchType.LAZY, cascade=CascadeType.PERSIST) @JoinTable(name = "album_media", joinColumns = { @JoinColumn(name = "media_id", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "album_id", nullable = false, updatable = false) }) public List<Album> getAlbums() {return albums;}
@ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "org_user_role_rel", joinColumns = {@JoinColumn(name = "user_id")}, inverseJoinColumns = {@JoinColumn(name = "role_id")}) @Where(clause="delete_flag=0") @OrderBy("no") public Set<Role> getRoles() { return roles; }
@ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "org_role_resource_rel", joinColumns = {@JoinColumn(name = "role_id")}, inverseJoinColumns = {@JoinColumn(name = "resources_id")}) public Set<Resource> getResources() { return resources; }
@ManyToMany @JoinTable( name="PERSISTENCE_ROSTER_TEAM_PLAYER", joinColumns= @JoinColumn(name="TEAM_ID", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="PLAYER_ID", referencedColumnName="ID") ) public Collection<Player> getPlayers() { return players; }
@Test public void roles() { ManyToMany manyToMany = ReflectTool.getMethodAnnotation(User.class, "getRoles", ManyToMany.class); Assert.assertEquals("", manyToMany.mappedBy()); Assert.assertEquals(FetchType.LAZY, manyToMany.fetch()); JoinTable joinTable = ReflectTool.getMethodAnnotation(User.class, "getRoles", JoinTable.class); Assert.assertEquals("user_role", joinTable.name()); Assert.assertEquals("users_id", joinTable.joinColumns()[0].name()); Assert.assertEquals("role_id", joinTable.inverseJoinColumns()[0].name()); }
private CascadeType[] getCascadeTypes(AccessibleObject accessibleObject) { CascadeType[] cascadeTypes = null; if(accessibleObject.isAnnotationPresent(OneToMany.class)) { cascadeTypes = accessibleObject.getAnnotation(OneToMany.class).cascade(); }else if(accessibleObject.isAnnotationPresent(ManyToOne.class)) { cascadeTypes = accessibleObject.getAnnotation(ManyToOne.class).cascade(); }else if(accessibleObject.isAnnotationPresent(ManyToMany.class)) { cascadeTypes = accessibleObject.getAnnotation(ManyToMany.class).cascade(); } return cascadeTypes; }
@ManyToMany @JoinTable(name="CODETEMPLATE_PROJECT", joinColumns= @JoinColumn(name="CODETEMPLATE_ID", referencedColumnName="ID"), inverseJoinColumns= @JoinColumn(name="PROJECT_ID", referencedColumnName="ID") ) public Set<ProjectEntity> getProjects() { return projects; }
@ManyToMany(fetch=FetchType.EAGER) @JoinTable( name="hel_usuari_permis", joinColumns= @JoinColumn(name="codi", referencedColumnName="codi"), inverseJoinColumns= @JoinColumn(name="permis", referencedColumnName="codi") ) @ForeignKey(name="hel_permis_usuari_fk", inverseName="hel_usuari_permis_fk") public Set<Permis> getPermisos() { return this.permisos; }
@ManyToMany(cascade = CascadeType.REFRESH, fetch = FetchType.LAZY) @JoinTable(name = "usuario_grupo", joinColumns = { @JoinColumn(name = "usuario_id", foreignKey = @ForeignKey(name = "fk_usuario_grupo_to_usuario") ) }, inverseJoinColumns = { @JoinColumn(name = "grupo_id", foreignKey = @ForeignKey(name = "fk_usuario_grupo_to_grupo")) }) public Set<Grupo> getGrupos() { return grupos; }
/** * 获取收藏商品 * * @return 收藏商品 */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_member_favorite_product") @OrderBy("createDate desc") public Set<Product> getFavoriteProducts() { return favoriteProducts; }
/** * 获取筛选品牌 * * @return 筛选品牌 */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_product_category_brand") @OrderBy("order asc") public Set<Brand> getBrands() { return brands; }
/** * 获取支持配送方式 * * @return 支持配送方式 */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_payment_shipping_method") @OrderBy("order asc") public Set<ShippingMethod> getShippingMethods() { return shippingMethods; }
/** * 获取角色 * * @return 角色 */ @NotEmpty @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_admin_role") public Set<Role> getRoles() { return roles; }
/** * 获取标签 * * @return 标签 */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_article_tag") @OrderBy("order asc") public Set<Tag> getTags() { return tags; }