2017-03-03 3 views
0

QueryDslに1つのクエリを書く際に問題があります。私はSQLでそれを書いた。ここではそれがどのように見えるかです:コレクションの入手方法<? QueryDslのBooleanExpessionからLong> extends

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))); 

をしかし、私は、このエラーメッセージが表示されます::

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)); 

私はこれを試してみました

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)) 

...またはそのようにする方法。

EDIT:の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> 

感謝。ミロラドシミック

答えて

0
あなたはこれを試すことができ

:私は私のPOMファイルにcom.mysema.querydslから何かを追加することで問題を抱えている

Predicate pred = QRestaurantTable.restaurantTable.id.notIn(new JPASubQuery() 
         .from(QReservation.reservation.restaurant) 
         .where(QReservation.reservation.restaurant.id.eq(id) 
            .and(QReservation.reservation.reservationBegin.notBetween(start, end)) 
            .and(QReservation.reservation.reservationEnd.notBetween(start, end))) 
         .list(QReservation.reservation.restaurantTable.id)); 
+0

。私はqueryDslのために私のpomのcom.querydslを使用します。 myshemaと置き換えようとすると、エラーが発生します:artifact com.myshema.querydsl:querydsl-jpa:jar:3.4.0がありません。プロジェクトをビルドできません。私はプロジェクトを更新してクリーンアップしようとしましたが、それと同じエラーです。 com.querydslはJPASubQueryクラスを持っていません。だから私はそれをテストすることはできません。 –

+0

あなたのポンを見せていただけますか? – artemisian

+0

投稿と固定クエリを編集しましたが、notIn()の前に1つの.eq(id)が見つかりませんでした。しかし、まだSQLクエリと同じではありません。 –