@Test public void testCascadeSomeWithDefaultPersist() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" ); assertAnnotationPresent( ManyToMany.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 4, relAnno.cascade().length ); assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] ); assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] ); assertEquals( CascadeType.DETACH, relAnno.cascade()[2] ); assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] ); }
/** * Make sure that it doesn't break the handler when {@link CascadeType#ALL} * is specified in addition to a default cascade-persist or individual * cascade settings. */ @Test public void testCascadeAllPlusMore() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" ); assertAnnotationPresent( ManyToMany.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 6, relAnno.cascade().length ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] ); assertEquals( CascadeType.MERGE, relAnno.cascade()[2] ); assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] ); assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] ); assertEquals( CascadeType.DETACH, relAnno.cascade()[5] ); }
@Test public void testCascadeAll() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" ); assertAnnotationPresent( ManyToMany.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 1, relAnno.cascade().length ); assertEquals( CascadeType.ALL, relAnno.cascade()[0] ); }
@Test public void testNoChildren() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( OrderBy.class ); assertAnnotationNotPresent( OrderColumn.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationNotPresent( Access.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.LAZY, relAnno.fetch() ); assertEquals( "", relAnno.mappedBy() ); assertEquals( void.class, relAnno.targetEntity() ); }
@Test public void testAllAttributes() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( OrderBy.class ); assertAnnotationNotPresent( OrderColumn.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationPresent( Access.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.EAGER, relAnno.fetch() ); assertEquals( "field2", relAnno.mappedBy() ); assertEquals( Entity3.class, relAnno.targetEntity() ); assertEquals( AccessType.PROPERTY, reader.getAnnotation( Access.class ) .value() ); }
Arrays.asList(m2mAnnotation.cascade()), Boolean.TRUE, m2mAnnotation.mappedBy(), Relation.ForeignKey.MANY_TO_MANY);
@Override protected CascadeType[] getCascade(Field field) { return field.getAnnotation(ManyToMany.class).cascade(); } };
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
/** * INTERNAL: (Overridden in XMLManyToManyAccessor) */ public List<String> getCascadeTypes() { return getCascadeTypes(m_manyToMany.cascade()); }
@Override public CascadeType[] getCascadeTypes() { return getRelationshipAnnotation().cascade(); }
collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade, false, false
/** * Retrieves cascade from metamodel attribute * * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }
/** * Retrieves cascade from metamodel attribute * * @param attribute given pluaral attribute * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }
private void introspectManyToMany(ManyToMany manyToMany) { Class targetClass = manyToMany.targetEntity(); if (! void.class.equals(targetClass)) setTargetEntity(targetClass); setCascadeTypes(manyToMany.cascade()); setFetch(manyToMany.fetch()); _mappedBy = manyToMany.mappedBy(); }
/** * @param member * the java member of attribute * @param name * the name of the attribute * @param manyToMany * the annotation * @param parsed * set of annotations parsed * * @since 2.0.0 */ public ManyToManyAttributeMetadataImpl(Member member, String name, ManyToMany manyToMany, Set<Class<? extends Annotation>> parsed) { super(member, name, parsed, manyToMany.targetEntity().getName(), manyToMany.fetch(), manyToMany.cascade()); parsed.add(ManyToMany.class); this.mappedBy = manyToMany.mappedBy(); this.mapKey = this.handleMapKey(member, parsed); this.mapKeyClassName = this.handleMapKeyClassName(member, parsed); this.mapKeyColumn = this.handleMapKeyColumn(member, parsed); this.mapKeyEnumType = this.handleMapKeyEnumType(member, parsed); this.mapKeyTemporalType = this.handleMapKeyTemporalType(member, parsed); this.orderBy = this.handleOrderBy(member, parsed); this.orderColumn = this.handleOrderColumn(member, parsed); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setManyToMany(true); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(TableJoin.LEFT_OUTER); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setManyToMany(true); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(TableJoin.LEFT_OUTER); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
collectionBinder.setCascadeStrategy( getCascadeStrategy( manyToManyAnn.cascade(), hibernateCascade, false, false