/** * * @return */ @ElementCollection(targetClass=EAuthority.class,fetch=FetchType.EAGER) @JoinTable(name = "grupo_autorities") @Enumerated(EnumType.STRING) @Fetch(FetchMode.SELECT) public List<EAuthority> getAuthorities() { return authorities; }
/** @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 void buildHierarchyColumnOverride(XClass element) { XClass current = element; Map<String, Column[]> columnOverride = new HashMap<String, Column[]>(); Map<String, JoinColumn[]> joinColumnOverride = new HashMap<String, JoinColumn[]>(); Map<String, JoinTable> joinTableOverride = new HashMap<String, JoinTable>(); while ( current != null && !mappings.getReflectionManager().toXClass( Object.class ).equals( current ) ) { if ( current.isAnnotationPresent( Entity.class ) || current.isAnnotationPresent( MappedSuperclass.class ) || current.isAnnotationPresent( Embeddable.class ) ) { //FIXME is embeddable override? Map<String, Column[]> currentOverride = buildColumnOverride( current, getPath() ); Map<String, JoinColumn[]> currentJoinOverride = buildJoinColumnOverride( current, getPath() ); Map<String, JoinTable> currentJoinTableOverride = buildJoinTableOverride( current, getPath() ); currentOverride.putAll( columnOverride ); //subclasses have precedence over superclasses currentJoinOverride.putAll( joinColumnOverride ); //subclasses have precedence over superclasses currentJoinTableOverride.putAll( joinTableOverride ); //subclasses have precedence over superclasses columnOverride = currentOverride; joinColumnOverride = currentJoinOverride; joinTableOverride = currentJoinTableOverride; } current = current.getSuperclass(); } holderColumnOverride = columnOverride.size() > 0 ? columnOverride : null; holderJoinColumnOverride = joinColumnOverride.size() > 0 ? joinColumnOverride : null; holderJoinTableOverride = joinTableOverride.size() > 0 ? joinTableOverride : null; }
private JoinTable buildJoinTable(Element tree, XMLContext.Default defaults) { Element subelement = tree == null ? null : tree.element( "join-table" ); final Class<JoinTable> annotationType = JoinTable.class; if ( subelement == null ) { return null; } //ignore java annotation, an element is defined AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType ); copyStringAttribute( annotation, subelement, "name", false ); copyStringAttribute( annotation, subelement, "catalog", false ); if ( StringHelper.isNotEmpty( defaults.getCatalog() ) && StringHelper.isEmpty( (String) annotation.valueOf( "catalog" ) ) ) { annotation.setValue( "catalog", defaults.getCatalog() ); } copyStringAttribute( annotation, subelement, "schema", false ); if ( StringHelper.isNotEmpty( defaults.getSchema() ) && StringHelper.isEmpty( (String) annotation.valueOf( "schema" ) ) ) { annotation.setValue( "schema", defaults.getSchema() ); } buildUniqueConstraints( annotation, subelement ); buildIndex( annotation, subelement ); annotation.setValue( "joinColumns", getJoinColumns( subelement, false ) ); annotation.setValue( "inverseJoinColumns", getJoinColumns( subelement, true ) ); return AnnotationFactory.create( annotation ); }
private List<AssociationOverride> buildAssociationOverrides(Element element, XMLContext.Default defaults) { List<Element> subelements = element == null ? null : element.elements( "association-override" ); List<AssociationOverride> overrides = new ArrayList<AssociationOverride>(); if ( subelements != null && subelements.size() > 0 ) { for ( Element current : subelements ) { AnnotationDescriptor override = new AnnotationDescriptor( AssociationOverride.class ); copyStringAttribute( override, current, "name", true ); override.setValue( "joinColumns", getJoinColumns( current, false ) ); JoinTable joinTable = buildJoinTable( current, defaults ); if ( joinTable != null ) { override.setValue( "joinTable", joinTable ); } overrides.add( (AssociationOverride) AnnotationFactory.create( override ) ); } } return overrides; }
@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; }
/** * Builds the name of the table of the association for the given field. * * @param attribute * the inspected field * @param override * contains optional override options * @param joinTable * the optional join table * @param collectionTable * the optional metadata of the table * @param defaultTableName * the default name for the table * @return the table name */ protected static String buildTableName(final AttributeAccessor attribute, final AssociationOverride override, final JoinTable joinTable, final CollectionTable collectionTable, final String defaultTableName) { if (override != null) { final JoinTable joinTableOverride = override.joinTable(); if (joinTableOverride != null && joinTableOverride.name().length() > 0) { return joinTableOverride.name(); } } if (joinTable != null && joinTable.name().length() > 0) { return joinTable.name(); } if (collectionTable != null && collectionTable.name().length() > 0) { return collectionTable.name(); } return defaultTableName; }
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable(name = "cellUpdateActivity", joinColumns = @JoinColumn(name = "cellId", nullable = false, updatable = false), inverseJoinColumns = @JoinColumn(name = "updateActivityId", nullable = false, updatable = false, unique = true)) @org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE }) @Sort(type = SortType.NATURAL) @ToMany(singularPropertyName = "updateActivity", hasNonconventionalMutation = true /* * model testing framework doesn't * understand this is a containment * relationship, and so requires * addUpdateActivity() method */) @Override public SortedSet<AdministrativeActivity> getUpdateActivities() { return _updateActivities; }
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE }) @JoinTable(name = "copyUpdateActivity", joinColumns = @JoinColumn(name = "copyId", nullable = false, updatable = false), inverseJoinColumns = @JoinColumn(name = "updateActivityId", nullable = false, updatable = false, unique = true)) @org.hibernate.annotations.Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE }) @Sort(type = SortType.NATURAL) @ToMany(singularPropertyName = "updateActivity", hasNonconventionalMutation = true /* * model testing framework doesn't * understand this is a containment * relationship, and so requires * addUpdateActivity() method */) @Override public SortedSet<AdministrativeActivity> getUpdateActivities() { return _updateActivities; }
/** * Get the set of user roles that this user belongs to. Do not modify the * contents of the returned collection: use * {@link #addScreensaverUserRole(ScreensaverUserRole)} or * {@link #removeScreensaverUserRole(ScreensaverUserRole)} instead. * * @return the set of user roles that this user belongs to */ @ElementCollection @edu.harvard.med.screensaver.model.annotations.ElementCollection(hasNonconventionalMutation = true /* * valid roles * depend upon * concrete entity * type */) @Column(name = "screensaverUserRole", nullable = false) @JoinTable(name = "screensaverUserRole", joinColumns = @JoinColumn(name = "screensaverUserId")) @org.hibernate.annotations.Type(type = "edu.harvard.med.screensaver.model.users.ScreensaverUserRole$UserType") @org.hibernate.annotations.ForeignKey(name = "fk_screensaver_user_role_type_to_screensaver_user") public Set<ScreensaverUserRole> getScreensaverUserRoles() { return _roles; }
/** * {@inheritDoc} */ // should really be one-to-many, but hibernate bug HHH-3160/HHH-1296 prevents reordering or deleting from the list // with a unique constraint on protocol_application @ManyToMany(fetch = FetchType.LAZY) @JoinTable( name = "biomaterial_protocol_application", joinColumns = @JoinColumn(name = "bio_material"), inverseJoinColumns = @JoinColumn(name = "protocol_application") ) @IndexColumn(name = "protocol_order") @ForeignKey(name = "biomaterial_protocol_application_bio_material_fk", inverseName = "biomaterial_protocol_application_protocol_application_fk") @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) public List<ProtocolApplication> getProtocolApplications() { return this.protocolApplications; }
/** * {@inheritDoc} */ // should really be one-to-many, but hibernate bug HHH-3160/HHH-1296 prevents reordering or deleting from the list // with a unique constraint on protocol_application @ManyToMany(fetch = FetchType.LAZY) @JoinTable( name = "hybridization_protocol_application", joinColumns = @JoinColumn(name = "hybridization"), inverseJoinColumns = @JoinColumn(name = "protocol_application") ) @IndexColumn(name = "protocol_order") @ForeignKey(name = "hybridization_protocol_application_hybridization_fk", inverseName = "hybridization_protocol_application_protocol_application_fk") @Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE, org.hibernate.annotations.CascadeType.DELETE_ORPHAN }) public List<ProtocolApplication> getProtocolApplications() { return this.protocolApplications; }
@ManyToMany(fetch = FetchType.LAZY) @MapKeyJoinColumn(name = "REAL_NETWORK_INTERFACE_ID", nullable = false) @JoinTable( name = "SIMULATION__" + "REAL_NETWORK_INTERFACE__" + "REAL_NETWORK_INTERFACE_CONFIGURATION", joinColumns = @JoinColumn(name = "SIMULATION_ID", nullable = false), inverseJoinColumns = @JoinColumn( name = "REAL_NETWORK_INTERFACE_CONFIGURATION_ID", nullable = false ) ) public Map<RealNetworkInterface, RealNetworkInterfaceConfiguration> getRealNetworkInterfaceConfigurations() { return realNetworkInterfaceConfigurations; }
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; }
/** * Get column overriding, property first, then parent, then holder * replace the placeholder 'collection&&element' with nothing * * These rules are here to support both JPA 2 and legacy overriding rules. */ @Override public JoinTable getJoinTable(XProperty property) { final String propertyName = StringHelper.qualify( getPath(), property.getName() ); JoinTable result = getOverriddenJoinTable( propertyName ); if (result == null) { result = property.getAnnotation( JoinTable.class ); } return result; }
/** * Get column overriding, property first, then parent, then holder * replace the placeholder 'collection&&element' with nothing * * These rules are here to support both JPA 2 and legacy overriding rules. */ public JoinTable getOverriddenJoinTable(String propertyName) { JoinTable result = getExactOverriddenJoinTable( propertyName ); if ( result == null && propertyName.contains( ".collection&&element." ) ) { //support for non map collections where no prefix is needed //TODO cache the underlying regexp result = getExactOverriddenJoinTable( propertyName.replace( ".collection&&element.", "." ) ); } return result; }
/** * Get column overriding, property first, then parent, then holder */ private JoinTable getExactOverriddenJoinTable(String propertyName) { JoinTable override = null; if ( parent != null ) { override = parent.getExactOverriddenJoinTable( propertyName ); } if ( override == null && currentPropertyJoinTableOverride != null ) { override = currentPropertyJoinTableOverride.get( propertyName ); } if ( override == null && holderJoinTableOverride != null ) { override = holderJoinTableOverride.get( propertyName ); } return override; }
private static Map<String, JoinTable> buildJoinTableOverride(XAnnotatedElement element, String path) { Map<String, JoinTable> tableOverride = new HashMap<String, JoinTable>(); if ( element == null ) return tableOverride; AssociationOverride singleOverride = element.getAnnotation( AssociationOverride.class ); AssociationOverrides multipleOverrides = element.getAnnotation( AssociationOverrides.class ); AssociationOverride[] overrides; if ( singleOverride != null ) { overrides = new AssociationOverride[] { singleOverride }; } else if ( multipleOverrides != null ) { overrides = multipleOverrides.value(); } else { overrides = null; } //fill overridden tables if ( overrides != null ) { for (AssociationOverride depAttr : overrides) { if ( depAttr.joinColumns().length == 0 ) { tableOverride.put( StringHelper.qualify( path, depAttr.name() ), depAttr.joinTable() ); } } } return tableOverride; }
@OneToMany(targetEntity = Goods8JPA.class, cascade = CascadeType.ALL, fetch = FetchType.EAGER) @JoinColumn(name = "join_user_goodsSet", foreignKey = @ForeignKey(name = "join_fk_user_goodsSet")) @JoinTable(name = "jpa_user_goodsSet_table", foreignKey = @ForeignKey(name = "table_user_goodsSet")) public Set<Goods8JPA> getGoods8JPASet() { return goods8JPASet; }
@OneToMany(targetEntity = Goods8JPA.class, cascade = ALL, fetch = EAGER) @JoinColumn(name = "join_goods_type_m2o", foreignKey = @ForeignKey(name = "fk_goods_type_m2o")) @JoinTable(name = "jpa_goods_type_set", foreignKey = @ForeignKey(name = "fk_jpa_goods_type_set")) public Set<Goods8JPA> getGoods8JPASet() { return goods8JPASet; }
@OneToMany(targetEntity = GoodsType8JPA.class, cascade = ALL, fetch = EAGER) @JoinColumn(name = "join_goods_children_m2o", foreignKey = @ForeignKey(name = "fk_goods_children_m2o")) @JoinTable(name = "jpa_goods_children_set", foreignKey = @ForeignKey(name = "fk_jpa_goods_children_set")) public Set<GoodsType8JPA> getChildrenSet() { return childrenSet; }
@OneToMany(targetEntity = Goods8JPA.class, cascade = REMOVE, fetch = EAGER) @JoinColumn(name = "join_goods_brand_m2o", foreignKey = @ForeignKey(name = "fk_goods_brand_m2o")) @JoinTable(name = "jpa_goods_brand_set", foreignKey = @ForeignKey(name = "fk_jpa_goods_brand_set")) public Set<Goods8JPA> getGoods8JPASet() { return goods8JPASet; }
@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()); }
@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; }
/** * 获取标签 * * @return 标签 */ @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "xx_product_tag") @OrderBy("order asc") public Set<Tag> getTags() { return tags; }