public static Map<String, ExtendedAttribute<?, ?>> getCollectionAttributeEntries(EntityMetamodel metamodel, EntityType<?> entityType, ExtendedAttribute<?, ?> attribute) { Map<String, ExtendedAttribute<?, ?>> collectionAttributeEntries = new HashMap<>(); JoinTable joinTable = attribute.getJoinTable(); if (joinTable == null) { throw new IllegalArgumentException("No support for inserting into inverse collection via DML API yet!"); } ExtendedManagedType<?> extendedManagedType = metamodel.getManagedType(ExtendedManagedType.class, entityType); for (String idAttributeName : joinTable.getIdAttributeNames()) { collectionAttributeEntries.put(idAttributeName, extendedManagedType.getAttribute(idAttributeName)); } if (((PluralAttribute<?, ?, ?>) attribute.getAttribute()).getElementType() instanceof ManagedType<?>) { String prefix = attribute.getAttributePathString() + "."; for (Map.Entry<String, ? extends ExtendedAttribute<?, ?>> entry : extendedManagedType.getAttributes().entrySet()) { if (entry.getKey().startsWith(prefix)) { collectionAttributeEntries.put(entry.getKey(), entry.getValue()); } } } collectionAttributeEntries.put(attribute.getAttributePathString(), attribute); return collectionAttributeEntries; }
@Override public JoinTable getJoinTable(EntityType<?> ownerType, String attributeName) { return entityMetamodel.getManagedType(ExtendedManagedType.class, ownerType.getName()).getAttribute(attributeName).getJoinTable(); }
if (returningAttribute.get(i).isCollection()) { sb.setLength(sb.length() - 1); joinTable = mainQuery.metamodel.getManagedType(ExtendedManagedType.class, entityType.getJavaType()).getAttribute(sb.toString()).getJoinTable(); sb.setLength(0);
columnTypes = entry.getColumnTypes(); } else { Collection<String> types = entry.getJoinTable().getKeyColumnTypes().values(); columnTypes = types.toArray(new String[types.size()]);
Map<String, String> keyColumnTypes = valuesLikeAttribute.getJoinTable().getKeyColumnTypes(); if (keyColumnTypes.size() != 1) { throw new IllegalArgumentException("Unsupported VALUES clause use with multi-column attribute type " + keyColumnTypes.values() + "! Consider creating a synthetic type like a @CTE entity to hold this attribute and use that type via fromIdentifiableValues instead!");
protected boolean determineForcedUnique(MetamodelBuildingContext context) { if (isCollection() && getMapping() != null && getMapping().indexOf('.') == -1) { ExtendedManagedType<?> managedType = context.getEntityMetamodel().getManagedType(ExtendedManagedType.class, getDeclaringType().getJpaManagedType()); ExtendedAttribute<?, ?> attribute = managedType.getOwnedAttributes().get(getMapping()); if (attribute != null && attribute.getAttribute() instanceof javax.persistence.metamodel.PluralAttribute<?, ?, ?>) { // TODO: we should add that information to ExtendedAttribute return (((javax.persistence.metamodel.PluralAttribute<?, ?, ?>) attribute.getAttribute()).getCollectionType() != javax.persistence.metamodel.PluralAttribute.CollectionType.MAP) && (!StringUtils.isEmpty(attribute.getMappedBy()) || !attribute.isBag()) && (attribute.getJoinTable() == null || attribute.getJoinTable().getKeyColumnMappings() == null) && !MetamodelUtils.isIndexedList(context.getEntityMetamodel(), context.getExpressionFactory(), managedType.getType().getJavaType(), getMapping()); } } return false; }
Map.Entry<String, ExtendedAttribute> entry = iterator.next(); ExtendedAttribute attributeEntry = entry.getValue(); JoinTable joinTable = attributeEntry.getJoinTable(); if (joinTable == null && !"".equals(attributeEntry.getMappedBy()) && (entityMetamodel.getEntity(attributeEntry.getElementClass()) == null || !attributeEntry.isDeleteCascaded())) { iterator.remove();