我想要mysql别名查询结果在querydsl中

时间:2019-07-04 01:52:47

标签: java mysql jpa querydsl

我想在querydsl中使用mysql别名查询结果。 我尝试过,但是发生以下无效路径错误。

MySql,java,queryDsl

QBoard qBoard = QBoard.board;
JPAQuery<BoardDto> query = new JPAQuery<>(entityManager);
BooleanBuilder builder = new BooleanBuilder();

Path<Board> board= Expressions.path(Board.class, "board");
StringPath boardYn= Expressions.stringPath(board, "boardYn");
builder.and(boardYn.eq("N"));

builder.and(qBoard .boardSeq.eq(1));

BoardDto boardDto = query.select(Projections.bean(BoardDto.class, 
qBoard.name, 
qBoard.title,
new CaseBuilder()
.when(qBoard.title.eq("test1").then("Y"))
.otherwise("N').as("boardYn")
))
.from(qBoard)
.where(builder)
.fetchOne();


[real query]
select
    name,
    title,
    case when title = 'test1' then 'Y' else 'N'
    end as boardYn
from board
where board_seq = 1 and boardYn = 'N'
  

org.hibernate.hql.internal.ast.InvalidPathException:无效路径:“ board.boardYn”

0 个答案:

没有答案