Refine search
/** * @author Oliver Gierke */ @Entity(name = "SampleOrder") @Data public class Order { @Id @GeneratedValue// private Long id; @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)// private List<LineItem> items = new ArrayList<>(); @ManyToOne// private Customer customer; public Order add(LineItem item) { this.items.add(item); return this; } }
if (null != ann.targetEntity() && !ann.targetEntity().getSimpleName().equals("void")) targetEntity = ann.targetEntity(); Relation relation = new Relation(relationField, targetEntity, relationField.getType(), ann.fetch(), Arrays.asList(ann.cascade()), Boolean.TRUE, ann.mappedBy(), Relation.ForeignKey.ONE_TO_MANY); relation.setJoinColumnName(StringUtils.isBlank(joinColumnAnn.name()) ? relationField.getName() : joinColumnAnn.name()); if (mappedField != null && mappedField.isAnnotationPresent(JoinColumn.class)) joinColumnName = mappedField.getAnnotation(JoinColumn.class).name();
mappedBy = oneToManyAnn.mappedBy(); collectionBinder.setTargetEntity( context.getBootstrapContext().getReflectionManager().toXClass( oneToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
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; }
FetchType fetchType; if ( oneToMany != null ) { fetchType = oneToMany.fetch();
/** * INTERNAL: (Overridden in XMLOneToManyAccessor) */ public List<String> getCascadeTypes() { if (m_oneToMany == null) { return new ArrayList<String>(); } else { return getCascadeTypes(m_oneToMany.cascade()); } }
private void readToOne(OneToMany 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); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
mappedBy = oneToManyAnn.mappedBy(); collectionBinder.setTargetEntity( mappings.getReflectionManager().toXClass( oneToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
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; }
FetchType fetchType; if ( oneToMany != null ) { fetchType = oneToMany.fetch();
@Entity @Table(name = "PARENT") private static class Parent { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, fetch = FetchType.LAZY, orphanRemoval = true) List<Child> children; void setChildren(List<Child> children) { this.children = children; } }
private void introspectOneToMany(OneToMany oneToMany) { Class targetClass = oneToMany.targetEntity(); if (! void.class.equals(targetClass)) setTargetEntity(targetClass); setCascadeTypes(oneToMany.cascade()); setFetch(oneToMany.fetch()); _mappedBy = oneToMany.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(); }
@Entity(name = "BaseTestEntity") @Table(name = "BASE_TEST_ENTITY") public static class BaseTestEntity { @Id @GeneratedValue Long id; @OneToMany Set<TestEntity> entities; }