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 = Arrays.<Expression<?>> asList(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 = Arrays.asList(lhs, rhs);
            }
        }

        super.visitOperation(type, operator, args);
    }
{@code JPQLSerializer} serializes Querydsl expressions into JPQL syntax.

@author tiwe
querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLSerializer.java