Spring Data和QueryDSL查询返回错误的类型(com.querydsl.core.support.QueryBase<>)

时间:2016-05-23 14:09:14

标签: java spring querydsl

我正在使用postgreSQL和JPA开发我的第一个Spring项目,我喜欢它,但现在我被卡住了。 我使用了Spring中的findBy ...方法,现在我也想使用QueryDSL进行带有可选参数的动态查询..

所以我添加了依赖词:

event.preventDefault();

和插件

<dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>4.1.1</version>
    </dependency>

    <dependency>
        <groupId>com.querydsl</groupId>
        <artifactId>querydsl-apt</artifactId>
        <version>4.1.1</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.7</version>
        <scope>runtime</scope>
    </dependency>

好的,我有一个Domain,Person Class:

<plugin>
    <groupId>com.mysema.maven</groupId>
    <artifactId>apt-maven-plugin</artifactId>
    <version>1.1.3</version>
    <executions>
      <execution>
        <goals>
          <goal>process</goal>
        </goals>
        <configuration>
          <outputDirectory>target/generated-sources/java</outputDirectory>
          <processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
        </configuration>
      </execution>
    </executions>
  </plugin>

...

和存储库:

@Entity
public class Person implements Serializable {
@Id
private Long personId;
private String firstname;
private String lastname;
private Date birthdate;

和Servie ..

public interface PersonRepository extends JpaRepository<Person, Long> {
    List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname);
    List<Person> findByBirthdate(Date birthdate);
}

PersonServiseImpl ..

所以,如果我是对的,我可以在Person Domain Package中创建一个新类,例如

public interface PersonService {
    public Person save(Person person);
    public Person findOne(Long personId);
    public List<Person> findAll();
    public List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname);
    List<Person> findByBirthdate(Date birthdate);
}

如果我这样做,我会得到一个&#34;不兼容的类型&#34;错误,需要:domain.Person找到:com.querydsl.core.support.QueryBase&lt;&gt;

0 个答案:

没有答案