public static CascadeStyle cascadeTypeToCascadeStyle(CascadeType cascadeType) { switch ( cascadeType ) { case ALL: { return CascadeStyles.ALL; } case PERSIST: { return CascadeStyles.PERSIST; } case MERGE: { return CascadeStyles.MERGE; } case REMOVE: { return CascadeStyles.DELETE; } case REFRESH: { return CascadeStyles.REFRESH; } case DETACH: { return CascadeStyles.EVICT; } default: { throw new AssertionFailure( "Unknown cascade type" ); } } }
@Test public void testJavaTypes() { // create an entity with multiple java types final SystemDialect dial = new SystemDialect(); dial.setDialBool(true); dial.setDialChar("char"); dial.setDialDate(new GregorianCalendar(2012, 02, 10).getTime()); dial.setDialDouble(15.0); dial.setDialEnum(CascadeType.PERSIST); dial.setDialLong(15L); dial.setDialShort((short) 1); // persist and flush em.persist(dial); em.flush(); em.clear(); // read entity from database and test values final SystemDialect dialFromDb = em.find(SystemDialect.class, dial.getId()); Assert.assertEquals(dial.getDialChar(), dialFromDb.getDialChar()); Assert.assertEquals(dial.getDialBool(), dialFromDb.getDialBool()); Assert.assertEquals(dial.getDialDate(), dialFromDb.getDialDate()); Assert.assertEquals(dial.getDialDouble(), dialFromDb.getDialDouble(),0.00001); Assert.assertEquals(dial.getDialEnum(), dialFromDb.getDialEnum()); Assert.assertEquals(dial.getDialLong(), dialFromDb.getDialLong()); Assert.assertEquals(dial.getDialShort(), dialFromDb.getDialShort()); }
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; }
private boolean hasCascadeAll(CascadeType[] cascades) { for( CascadeType type : cascades ) { if( CascadeType.ALL == type || CascadeType.REMOVE == type ) { return true; } } return false; }
@OneToMany(cascade = CascadeType.ALL, mappedBy = "bundle") @Fetch(value = FetchMode.SELECT) @MapKey(name = "locale") public Map<String, LanguageString> getStrings() { return strings; }
private void getCascades(AnnotationDescriptor ad, Element element, XMLContext.Default defaults) { List<Element> elements = element != null ? element.elements( "cascade" ) : new ArrayList<Element>( 0 ); List<CascadeType> cascades = new ArrayList<CascadeType>(); for ( Element subelement : elements ) { if ( subelement.element( "cascade-all" ) != null ) { cascades.add( CascadeType.ALL ); } if ( subelement.element( "cascade-persist" ) != null ) { cascades.add( CascadeType.PERSIST ); } if ( subelement.element( "cascade-merge" ) != null ) { cascades.add( CascadeType.MERGE ); } if ( subelement.element( "cascade-remove" ) != null ) { cascades.add( CascadeType.REMOVE ); } if ( subelement.element( "cascade-refresh" ) != null ) { cascades.add( CascadeType.REFRESH ); } if ( subelement.element( "cascade-detach" ) != null ) { cascades.add( CascadeType.DETACH ); } } if ( Boolean.TRUE.equals( defaults.getCascadePersist() ) && !cascades.contains( CascadeType.ALL ) && !cascades.contains( CascadeType.PERSIST ) ) { cascades.add( CascadeType.PERSIST ); } if ( cascades.size() > 0 ) { ad.setValue( "cascade", cascades.toArray( new CascadeType[cascades.size()] ) ); } }
private Set<CascadeType> determineCascadeTypes(AnnotationInstance associationAnnotation) { Set<CascadeType> cascadeTypes = new HashSet<CascadeType>(); AnnotationValue cascadeValue = associationAnnotation.value( "cascade" ); if ( cascadeValue != null ) { String[] cascades = cascadeValue.asEnumArray(); for ( String s : cascades ) { cascadeTypes.add( Enum.valueOf( CascadeType.class, s ) ); } } return cascadeTypes; }
public static Set<CascadeStyle> cascadeTypeToCascadeStyleSet(Set<CascadeType> cascadeTypes) { if ( CollectionHelper.isEmpty( cascadeTypes ) ) { return Collections.emptySet(); } Set<CascadeStyle> cascadeStyleSet = new HashSet<CascadeStyle>(); for ( CascadeType cascadeType : cascadeTypes ) { cascadeStyleSet.add( cascadeTypeToCascadeStyle( cascadeType ) ); } return cascadeStyleSet; }
@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; }
@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;}
@OneToOne(cascade = CascadeType.PERSIST) @JoinColumns ({ @JoinColumn(name = "view" , referencedColumnName = "dataid" ), @JoinColumn(name = "creater" , referencedColumnName = "creater" ) }) public TopicView getView() { return view; }
/** * Get all comments for current blog entry. * * @return List of all comments for current blog entry. */ @OneToMany(mappedBy = "blogEntry", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true) @OrderBy("postedOn") public List<BlogComment> getComments() { return comments; }
/** * Gets all blog entries for which current user is author. * * @return List of current user blog entries. */ @OneToMany(mappedBy = "creator", fetch = FetchType.LAZY, cascade = CascadeType.PERSIST, orphanRemoval = true) @OrderBy("createdAt") public List<BlogEntry> getEntries() { return entries; }
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; }
/** * @return code */ @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL) @JoinColumn(name = "idCode") public AccessCodeEntity getCode() { return this.code; }
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true) @JoinColumn(name = "user_id", insertable = false, nullable = false, updatable = false) // MOSCOW @Fetch(FetchMode.SELECT) // Это отсечение дублирования при джойне таблици, т.к. в QPlanService есть @OneToOne к QService, и в нем есть @OneToMany к QServiceLang - дублится по // количеству переводов // This is the truncation of the duplication when the table joins, since In QPlanService there is @OneToOne to QService, and there is @OneToMany to // QServiceLang - it is duplicated by the number of translations. public List<QPlanService> getPlanServices() { return planServices; }
@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; }
@ManyToMany(cascade = { CascadeType.ALL },fetch=FetchType.EAGER) @JoinTable(name = "ContactToContactJoinTable", joinColumns = @JoinColumn(name = "parentContactId"), inverseJoinColumns = @JoinColumn(name = "childContactId")) @XmlTransient public Set<Contact> getContactChildren() { return contactChildren; }
@Override @OneToMany(targetEntity = MCRCategoryImpl.class, cascade = { CascadeType.ALL }, mappedBy = "parent") @OrderColumn(name = "positionInParent") @Access(AccessType.FIELD) public List<MCRCategory> getChildren() { return super.getChildren(); }
/** * 获取参数 * * @return 参数 */ @JsonProperty @Valid @NotEmpty @OneToMany(mappedBy = "parameterGroup", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("order asc") public List<Parameter> getParameters() { return parameters; }
/** * 获取订单项 * * @return 订单项 */ @Valid @NotEmpty @OneToMany(mappedBy = "order", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("isGift asc") public List<OrderItem> getOrderItems() { return orderItems; }
/** * 获取发货项 * * @return 发货项 */ @Valid @NotEmpty @OneToMany(mappedBy = "shipping", fetch = FetchType.LAZY, cascade = CascadeType.ALL) public List<ShippingItem> getShippingItems() { return shippingItems; }
/** * 获取规格值 * * @return 规格值 */ @Valid @NotEmpty @OneToMany(mappedBy = "specification", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true) @OrderBy("order asc") public List<SpecificationValue> getSpecificationValues() { return specificationValues; }
/** * 获取退货项 * * @return 退货项 */ @Valid @NotEmpty @OneToMany(mappedBy = "returns", fetch = FetchType.LAZY, cascade = CascadeType.ALL) public List<ReturnsItem> getReturnsItems() { return returnsItems; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="order") public Set<OrderDetail> getOrderDetails() { return this.orderDetails; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="product") public Set<OrderDetail> getOrderDetails() { return this.orderDetails; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="office") public Set<Employee> getEmployees() { return this.employees; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="company") public Set<Department> getDepartments() { return this.departments; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="company") public Set<Employee> getEmployees() { return this.employees; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="department") public Set<Employee> getEmployees() { return this.employees; }
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="department") public Set<Department> getDepartments() { return this.departments; }
public Set<CascadeType> getCascadeTypes() { return cascadeTypes; }
@XmlTransient @LazyCollection(LazyCollectionOption.EXTRA) @ManyToMany(fetch = FetchType.LAZY, mappedBy = "albums", cascade=CascadeType.PERSIST) public List<Media> getMedia() {return media;}
@XmlTransient @LazyCollection(LazyCollectionOption.EXTRA) @OneToMany(mappedBy = "user", orphanRemoval=true, fetch=FetchType.LAZY, cascade=CascadeType.ALL) public List<Media> getMedia() {return media;}
@XmlTransient @LazyCollection(LazyCollectionOption.EXTRA) @OneToMany(mappedBy = "user", orphanRemoval=true, fetch=FetchType.LAZY, cascade=CascadeType.ALL) public List<Share> getShares() {return shares;}