Refine search
/** * @author Emmanuel Bernard */ @Entity public class Trousers { @Id public Integer id; @OneToOne @JoinColumn(name = "zip_id") public TrousersZip zip; }
List<CascadeType> cascades = new ArrayList<>( Arrays.asList( oneToOne.cascade() ) ); if ( !cascades.contains( CascadeType.ALL ) && !cascades.contains( CascadeType.PERSIST ) ) { cascades.add( CascadeType.PERSIST ); ad.setValue( "targetEntity", oneToOne.targetEntity() ); ad.setValue( "fetch", oneToOne.fetch() ); ad.setValue( "optional", oneToOne.optional() ); ad.setValue( "mappedBy", oneToOne.mappedBy() ); ad.setValue( "orphanRemoval", oneToOne.orphanRemoval() );
/** * @author Emmanuel Bernard */ @Entity public class ExclusiveDependent { @EmbeddedId DependentId id; @JoinColumn(name = "FK", nullable = false) // id attribute mapped by join column default @MapsId("empPK") // maps empPK attribute of embedded id @OneToOne Employee emp; }
@OneToOne(fetch = FetchType.LAZY) @JoinColumn(name = "terminal_id") public Device getDevice() { return device; }
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(); }
protected boolean isMandatory(Field field) { OneToMany oneToManyAnnotation = field.getAnnotation(OneToMany.class); ManyToMany manyToManyAnnotation = field.getAnnotation(ManyToMany.class); if (oneToManyAnnotation != null || manyToManyAnnotation != null) { return false; } Column columnAnnotation = field.getAnnotation(Column.class); OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class); com.haulmont.chile.core.annotations.MetaProperty metaPropertyAnnotation = field.getAnnotation(com.haulmont.chile.core.annotations.MetaProperty.class); boolean superMandatory = (metaPropertyAnnotation != null && metaPropertyAnnotation.mandatory()) || (field.getAnnotation(NotNull.class) != null && isDefinedForDefaultValidationGroup(field.getAnnotation(NotNull.class))); // @NotNull without groups return (columnAnnotation != null && !columnAnnotation.nullable()) || (oneToOneAnnotation != null && !oneToOneAnnotation.optional()) || (manyToOneAnnotation != null && !manyToOneAnnotation.optional()) || superMandatory; }
@Override protected CascadeType[] getCascade(Field field) { return field.getAnnotation(OneToOne.class).cascade(); } },
fetchType = oneToOne.fetch();
/** * INTERNAL: */ public boolean isOptional() { return (m_oneToOne == null) ? true : m_oneToOne.optional(); }
/** * @author Emmanuel Bernard */ @Entity public class MedicalHistory { //all attributes map to relationship: AttributeOverride not allowed @EmbeddedId PersonId id; @MapsId @JoinColumns({ @JoinColumn(name = "FK1", referencedColumnName = "firstName"), @JoinColumn(name = "FK2", referencedColumnName = "lastName") }) @OneToOne Person patient; }
@OneToOne @JoinColumn(name = "id") @MapsId public Post getPost() { return post; }
OneToOne oneToOneAnn = property.getAnnotation( OneToOne.class ); String mappedBy = oneToOneAnn != null ? oneToOneAnn.mappedBy() : null; joinColumns = Ejb3JoinColumn.buildJoinColumns(
/** * INTERNAL: (Overridden in XMLOneToOneAccessor) */ public List<String> getCascadeTypes() { if (m_oneToOne == null) { return new ArrayList<String>(); } else { return getCascadeTypes(m_oneToOne.cascade()); } }
@Override protected String getFetch(Field field) { return field.getAnnotation(OneToOne.class).fetch().name(); } @Override
protected boolean isRequired(MetaProperty metaProperty) { if (metaProperty.isMandatory()) return true; ManyToOne many2One = metaProperty.getAnnotatedElement().getAnnotation(ManyToOne.class); if (many2One != null && !many2One.optional()) return true; OneToOne one2one = metaProperty.getAnnotatedElement().getAnnotation(OneToOne.class); return one2one != null && !one2one.optional(); }
/** * @author Emmanuel Bernard */ @Entity public class MedicalHistory { //all attributes map to relationship: AttributeOverride not allowed @EmbeddedId PersonId id; @MapsId @JoinColumns({ @JoinColumn(name = "FK1", referencedColumnName = "firstName"), @JoinColumn(name = "FK2", referencedColumnName = "lastName") }) @OneToOne Person patient; }