springboot version is 2.51, java vsersion 1.8 it will crash in selectFrom(), erro info: java.lang.NoSuchFieldError: TREATED_PATH
how to resolve it,i cant find a way in web
there is my code
@SpringBootTest class Demo4ApplicationTests { @Resource private BmsPostRepository bm; @Autowired private JPAQueryFactory queryFactory; @Test void contextLoads() { var tab="hot"; var page = PageRequest.of(pageNo, pageSize); var t = QBmsPost.bmsPost; var u = QUmsUser.umsUser; var now = new Date(); var tomorrow = DateUtils.addDays(now, 1); var query = queryFactory .selectFrom(t) .leftJoin(u) .on(t.userId.eq(u.id)); if (tab.equals("hot")) query = query.where(t.createTime.lt(tomorrow)); var re = (!tab.equals("hot")) ? query.orderBy(t.createTime.desc()) : query.orderBy(t.view.desc(), t.createTime.desc()); var er =re.fetch(); } }
there is dependency
<dependency> <scope>compile</scope> <groupId>com.querydsl</groupId> <artifactId>querydsl-jpa</artifactId> <version>5.0.0.M1</version> </dependency> <dependency> <scope>provided</scope> <groupId>com.querydsl</groupId> <artifactId>querydsl-apt</artifactId> <version>5.0.0.M1</version> </dependency>
java.lang.NoSuchFieldError: TREATED_PATH at com.querydsl.jpa.JPQLTemplates.<init>(JPQLTemplates.java:147) at com.querydsl.jpa.JPQLTemplates.<init>(JPQLTemplates.java:51) at com.querydsl.jpa.JPQLTemplates.<clinit>(JPQLTemplates.java:46) at com.querydsl.jpa.impl.JPAProvider.<clinit>(JPAProvider.java:59) at com.querydsl.jpa.impl.JPAQuery.<init>(JPAQuery.java:48) at com.querydsl.jpa.impl.JPAQueryFactory.query(JPAQueryFactory.java:138) at com.querydsl.jpa.impl.JPAQueryFactory.select(JPAQueryFactory.java:72) at com.querydsl.jpa.impl.JPAQueryFactory.selectFrom(JPAQueryFactory.java:102) at com.example.demo.Demo4ApplicationTests.contextLoads(Demo4ApplicationTests.java:31
Advertisement
Answer
You have mixed versions of querydsl. I guess you are having querydsl-core version 4.4.x while your querydsl-jpa is of version 5.0.0.M1. (this is probably caused by a spring-boot starter library.)
Anyhow, this can easily fixed by explicitely adding the correct version of querydsl-core as dependency.
<dependency> <groupId>com.querydsl</groupId> <artifactId>querydsl-core</artifactId> <version>5.0.0.M1</version> </dependency>