Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] jpql 코드로 복구 #115

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import com.querydsl.jpa.JPAExpressions;
import javax.persistence.NoResultException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
Expand Down Expand Up @@ -41,7 +42,7 @@ public Optional<Parentchild> findByUserId(Long userId) {

public Optional<User> findMatchUserByUserId(Long userId) {

QUser user = QUser.user;
/*QUser user = QUser.user;
QUser uc = new QUser("uc");

return Optional.ofNullable(queryFactory
Expand All @@ -53,7 +54,22 @@ public Optional<User> findMatchUserByUserId(Long userId) {
.from(uc)
.where(uc.id.eq(userId))
)))
.fetchOne());
.fetchOne());*/

String jpql = "SELECT u FROM User u " +
"JOIN User uc ON uc.parentChild = u.parentChild " +
"WHERE uc.id = :id AND uc.id != u.id";

try {
User user = em.createQuery(jpql, User.class)
.setParameter("id", userId)
.getSingleResult();
return Optional.ofNullable(user);
} catch (NoResultException e) {
return Optional.empty();
} finally {
em.close();
}
}

public List<String> findFcmTokensById(Long parentchildId) {
Expand Down
Loading