/** * Resolves the column for the {@code id property} of this entity class. * * @param attribute * the referencing attribute (for evaluating annotations) * * @return the column name * @throws IllegalStateException * if the id property is not singular and no MapsId is given */ GeneratorColumn getIdColumn(final AttributeAccessor attribute) { if (this.idProperty instanceof SingularProperty) { return ((SingularProperty<?, ?>) this.idProperty).getColumn(); } if (this.idProperty instanceof EmbeddedProperty) { final MapsId mapsId = attribute.getAnnotation(MapsId.class); if (mapsId != null && mapsId.value().length() > 0) { final Property<?, ?> property = ((EmbeddedProperty<E, ?>) this.idProperty).getEmbeddedProperties() .get(mapsId.value()); if (property instanceof SingularProperty) { return ((SingularProperty<?, ?>) this.idProperty).getColumn(); } } throw new ModelException(attribute + " misses MapId for a singular property in " + this.entityClass); } if (this.idProperty == null && this.parentEntityClass != null) { // It seems we are still building the hierarchy this.idProperty = this.context.getDescription(this.parentEntityClass).getIdProperty(); if (this.idProperty != null) { return getIdColumn(attribute); } } throw new ModelException(attribute + " does not reference an ID column in " + this.entityClass); }
public void addPropertyAnnotatedWithMapsId(XClass entityType, PropertyData property) { Map<String, PropertyData> map = propertiesAnnotatedWithMapsId.get( entityType ); if ( map == null ) { map = new HashMap<String, PropertyData>(); propertiesAnnotatedWithMapsId.put( entityType, map ); } map.put( property.getProperty().getAnnotation( MapsId.class ).value(), property ); }
/** * Adds a @MapsId annotation to the specified annotationList if the specified element has the * maps-id attribute set. This should only be the case for many-to-one or one-to-one * associations. */ private void getMapsId(List<Annotation> annotationList, Element element) { String attrVal = element.attributeValue( "maps-id" ); if ( attrVal != null ) { AnnotationDescriptor ad = new AnnotationDescriptor( MapsId.class ); ad.setValue( "value", attrVal ); annotationList.add( AnnotationFactory.create( ad ) ); } }
@ForeignKey(name = "none") @MapsId("record") @ManyToOne(fetch = FetchType.LAZY) @JoinColumns({ @JoinColumn(name = COLUMN_RECORD_ID, referencedColumnName = "id") }) public RAuditEventRecord getRecord() { return record; }
/** * Creates a new instance of {@link EntityProperty}. * * @param context * the generator context. * @param containerTable * the table that contains our column * @param attribute * the accessor of the attribute * @param override * optional {@link AttributeOverride} configuration. */ public EntityProperty(final GeneratorContext context, final GeneratorTable containerTable, final AttributeAccessor attribute, @Nullable final AssociationOverride override) { super(attribute); this.context = context; // Initialize the target class description this.targetClass = context.getDescription((Class<T>) attribute.getType()); // Initialize according to the *ToOne annotations final MappingInformation mapping = new MappingInformation(attribute); this.required = !mapping.isOptional(); this.mappedBy = mapping.getMappedBy().length() == 0 ? null : mapping.getMappedBy(); final MapsId mapsId = attribute.getAnnotation(MapsId.class); this.idField = mapsId != null ? mapsId.value() : null; // Initialize the column name if (this.mappedBy == null) { final JoinColumn joinColumn = override != null && override.joinColumns().length > 0 ? override.joinColumns()[0] : attribute.getAnnotation(JoinColumn.class); if (joinColumn != null && joinColumn.name().length() > 0) { this.column = containerTable.resolveColumn(joinColumn.name()); } else { this.column = containerTable.resolveColumn(attribute.getName() + "_" + (this.targetClass == null ? "id" : this.targetClass.getIdColumn(attribute))); } } else { this.column = null; } // Initialize ANY meta information final String anyColumnName = mapping.getAnyMetaColumn(); if (anyColumnName != null) { this.anyColumn = containerTable.resolveColumn(anyColumnName); fillMetaDefs(attribute, context.getDialect()); } else { this.anyColumn = null; } }
@MapsId("processId") @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "PROCESS_ID", insertable = false, updatable = false) public ModelRatingResults getModelRatingResults() { return this.modelRatingResults; }
@JoinColumn(name = "ID2", nullable = false) @ManyToOne @MapsId(value = "id2") public UseCase2 getId2() { return id2; }
private static String findMappedId(final AttributeAccessor attribute) { final MapsId mapsId = attribute.getAnnotation(MapsId.class); return mapsId == null || mapsId.value().length() == 0 ? null : mapsId.value(); }
/** * Return true if MapsId annotation is define on a field. * @param field the field * @return true/false. */ public static boolean isMapsId(final Field field) { return field.getAnnotation(MapsId.class) != null; }
/** * Get field name from MapsId annotation. * @param field the field * @return the field name. */ public static String getMapsIdValue(final Field field) { final MapsId m = field.getAnnotation(MapsId.class); return m == null ? null : m.value(); }