【发布时间】:2017-07-24 04:53:41
【问题描述】:
我在 QueryDsl 中编写一个查询时遇到问题。我用sql写的。下面是它的样子:
select * from isa_proj.restaurant_table where isa_proj.restaurant_table.id not in
(SELECT restaurant_table_id FROM isa_proj.reservation r where r.restaurant_id = 1 AND
reservation_begin not between CAST('2017-02-17 7:30' AS datetime) and CAST('2017-02-17 9:30' AS datetime) and
reservation_expire not between CAST('2017-02-17 7:30' AS datetime) and CAST('2017-02-17 9:30' AS datetime));
我试过这个:
Predicate pred = QRestaurantTable.restaurantTable.id.eq(id).notIn(QReservation.reservation.restaurant.id.eq(id).and(
QReservation.reservation.reservationBegin.notBetween(start, end)).and(
QReservation.reservation.reservationEnd.notBetween(start, end)));
但我收到此错误消息:
The method notIn(Number...) in the type NumberExpression<Long> is not applicable for the arguments (BooleanExpression)
这是我第一次使用 QueryDsl。我不知道如何从以下位置获取 restaurant_table_id:
QReservation.reservation.restaurant.id.eq(id).and(
QReservation.reservation.reservationBegin.notBetween(start, end)).and(
QReservation.reservation.reservationEnd.notBetween(start, end))
...或者如何正确地做到这一点。
编辑: pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>restaurant</groupId>
<artifactId>isa_proj</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>isa_proj</name>
<url>http://maven.apache.org</url>
<description>WEB application used for study purpose.</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.7</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- MYSQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- https://github.com/querydsl/apt-maven-plugin -->
<!--Dependency: https://mvnrepository.com/artifact/com.querydsl/querydsl-apt -->
<!-- <plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<version>1.1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>src/main/java/restaurant/jpa/domain/queries</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>4.1.4</version>
</dependency>
</dependencies>
</plugin> -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
谢谢。米洛拉德析米克
【问题讨论】:
标签: mysql hibernate predicate querydsl