/** * Returns the {@link SingularAttribute} representing the identifier of the given {@link EntityType} if it contains a * singular one. * * @param entityType must not be {@literal null}. * @return */ private static Optional<? extends SingularAttribute<?, ?>> getSingularIdAttribute(EntityType<?> entityType) { if (!entityType.hasSingleIdAttribute()) { return Optional.empty(); } return entityType.getSingularAttributes().stream() // .filter(SingularAttribute::isId) // .findFirst(); } }
@Override protected void renderArguments(StringBuilder buffer, RenderingContext renderingContext) { if ( isDistinct() ) { buffer.append("distinct "); } else { // If function specifies a single non-distinct entity with ID, its alias would normally be rendered, which ends up // converting to the column(s) associated with the entity's ID in the rendered SQL. However, some DBs don't support // the multiple columns that would end up here for entities with composite IDs. So, since we modify the query to // instead specify star since that's functionally equivalent and supported by all DBs. List<Expression<?>> argExprs = getArgumentExpressions(); if (argExprs.size() == 1) { Expression argExpr = argExprs.get(0); if (argExpr instanceof Root<?>) { Root<?> root = (Root<?>)argExpr; if (!root.getModel().hasSingleIdAttribute()) { buffer.append('*'); return; } } } } super.renderArguments(buffer, renderingContext); }
if (root.getModel().hasSingleIdAttribute()) {
/** * Returns the {@link SingularAttribute} representing the identifier of the given {@link EntityType} if it contains a * singular one. * * @param entityType must not be {@literal null}. * @return */ private static Optional<? extends SingularAttribute<?, ?>> getSingularIdAttribute(EntityType<?> entityType) { if (!entityType.hasSingleIdAttribute()) { return Optional.empty(); } return entityType.getSingularAttributes().stream() // .filter(SingularAttribute::isId) // .findFirst(); } }
final EntityType<? extends Object> et = em.getMetamodel().entity(entityClass); if (!et.hasSingleIdAttribute()) { throw new IllegalArgumentException("Dynamic EJB doesn't manage IdClass yet");
@Override public List<String> getIdentifierOrUniqueKeyEmbeddedPropertyNames(EntityType<?> ownerType, String attributeName) { Attribute<?, ?> attribute = getAttribute(ownerType, attributeName); if (((SingularAttribute<?, ?>) attribute).getType() instanceof EntityType<?>) { EntityType<?> entityType = (EntityType<?>) ((SingularAttribute<?, ?>) attribute).getType(); if (entityType.hasSingleIdAttribute()) { return Collections.singletonList(entityType.getId(entityType.getIdType().getJavaType()).getName()); } else { Set<SingularAttribute<?, ?>> attributes = (Set<SingularAttribute<?, ?>>) (Set) entityType.getIdClassAttributes(); List<String> attributeNames = new ArrayList<>(attributes.size()); for (Attribute<?, ?> attr : attributes) { attributeNames.add(attr.getName()); } return attributeNames; } } return Collections.emptyList(); }
final EntityType<? extends Object> et = em.getMetamodel().entity(entityClass); if (!et.hasSingleIdAttribute()) { throw new IllegalArgumentException("Dynamic EJB doesn't manage IdClass yet");
private void visitPathInCollection(Class<?> type, Operator operator, List<? extends Expression<?>> args) { Path<?> lhs = (Path<?>) args.get(0); @SuppressWarnings("unchecked") Constant<? extends Collection<?>> rhs = (Constant<? extends Collection<?>>) args.get(1); if (rhs.getConstant().isEmpty()) { operator = operator == Ops.IN ? Ops.EQ : Ops.NE; args = ImmutableList.of(Expressions.ONE, Expressions.TWO); } else if (entityManager != null && !templates.isPathInEntitiesSupported() && args.get(0).getType().isAnnotationPresent(Entity.class)) { final Metamodel metamodel = entityManager.getMetamodel(); final PersistenceUnitUtil util = entityManager.getEntityManagerFactory().getPersistenceUnitUtil(); final EntityType<?> entityType = metamodel.entity(args.get(0).getType()); if (entityType.hasSingleIdAttribute()) { SingularAttribute<?,?> id = getIdProperty(entityType); // turn lhs into id path lhs = ExpressionUtils.path(id.getJavaType(), lhs, id.getName()); // turn rhs into id collection Set<Object> ids = new HashSet<Object>(); for (Object entity : rhs.getConstant()) { ids.add(util.getIdentifier(entity)); } rhs = ConstantImpl.create(ids); args = ImmutableList.of(lhs, rhs); } } super.visitOperation(type, operator, args); }
if (entityType.hasSingleIdAttribute()) { return Collections.singletonList(entityType.getId(entityType.getIdType().getJavaType()).getName()); } else {
if (((SingularAttribute<?, ?>) attribute).getType() instanceof EntityType<?>) { EntityType<?> entityType = (EntityType<?>) ((SingularAttribute<?, ?>) attribute).getType(); if (entityType.hasSingleIdAttribute()) { Class<?> idClass = entityType.getIdType().getJavaType(); try {
if (((SingularAttribute<?, ?>) attribute).getType() instanceof EntityType<?>) { EntityType<?> entityType = (EntityType<?>) ((SingularAttribute<?, ?>) attribute).getType(); if (entityType.hasSingleIdAttribute()) { Class<?> idClass = entityType.getIdType().getJavaType(); try {
if (root.getModel().hasSingleIdAttribute()) {
!startType.hasSingleIdAttribute() || joinManager.getRoots().size() > 1 || clause == ClauseType.JOIN ||
private void addPrimaryKey(MetadataFactory mf, Metamodel model, EntityType<?> entity, Table entityTable) throws TranslatorException { if (entity.hasSingleIdAttribute()) { if (entity.getIdType().getPersistenceType().equals(PersistenceType.BASIC)) { SingularAttribute<?, ?> pkattr = entity.getId(entity.getIdType().getJavaType());
if (et.hasSingleIdAttribute()) { idAttribute = getIdAttribute(et);