Get "Invalid derived query" error all over the place in our Spring Data JpaRepository interfaces in STS 3.1
Asked Answered
H

4

24

We have implemented our repositories exactly as demonstrated in the Spring Data documentation. Everything was fine until we upgraded from STS 2.9 to STS 3.1. All attempts to get these errors to disappear have failed, and in some cases they don't even make sense! They don't match any properties in either the interface or the entities used!

Here is an example:

public interface CreditNotesRepository extends JpaRepository<CreditNotes, Long> {

    CreditNotes findCurrentCreditNotes(Long shipmentDetailId);
}

The findCurrentCreditNotes is a named query in our entity. This code executes perfectly fine.

@NamedQueries({
    @NamedQuery(name = "CreditNotes.getCount", query = "SELECT COUNT(f) FROM CreditNotes f"),
    @NamedQuery(name = "CreditNotes.findCurrentCreditNotes", query =
        "SELECT creditNotes FROM CreditNotes creditNotes"
        + " WHERE creditNotes.shipmentDetail.shipmentDetailId = ?1 "
        + " AND creditNotes.notesSeqNumber =  (SELECT max(creditNotes2.notesSeqNumber) FROM CreditNotes creditNotes2"
        + " WHERE creditNotes.shipmentDetail.shipmentDetailId = creditNotes2.shipmentDetail.shipmentDetailId)")
})

And the error we get:

Invalid derived query! No property find found for type ca.cole.freight.model.CreditNotes

Although this is just a flag (doesn't affect compilation), it is annoying and confusing. Can anyone shed some light on this? And explain it to me like I'm 6 years old! ;)

Hydride answered 25/10, 2012 at 15:55 Comment(0)
P
26

It's an IDE error explained in the following post:

http://forum.springsource.org/showthread.php?138585-Invalid-derived-query!-No-property-delete-found-for-type-java-lang-Object

In the meantime, you can turn off the validation in preferences/spring/project validators/Data validator uncheck invalid derived query and STS wont throw the marker anymore.

Pattiepattin answered 28/8, 2013 at 19:58 Comment(0)
R
34

At the post on the Spring Forum, Spring Team announced that

It is already fixed for STS 3.3.0

I didn't check this version yet. But I'm using 3.5.0.RELEASE and the problem comes back! My fix is to uncheck Invalid Derived Query

Invalid Derived Query

Rodie answered 16/4, 2014 at 16:39 Comment(5)
Also occurs in STS 3.6.3.RELEASEDevorahdevore
The issue is still present in STS 3.9.1 as well.Manthei
The issue is still in 3.9.4Famish
Its still in 3.9.5Nudge
it's Still in 3.9.8Gothenburg
P
26

It's an IDE error explained in the following post:

http://forum.springsource.org/showthread.php?138585-Invalid-derived-query!-No-property-delete-found-for-type-java-lang-Object

In the meantime, you can turn off the validation in preferences/spring/project validators/Data validator uncheck invalid derived query and STS wont throw the marker anymore.

Pattiepattin answered 28/8, 2013 at 19:58 Comment(0)
T
15

There is also workaround for this. Add @Query annotation on your method definition in Your repository without JPQL/SQL query defined.

Here is example :

@Query
List<OwnerModel> findByFirstNameAndAgeNotZero(@Param(value = "firstName") String firstName);

In this case named query OrderModel.findByFirstNameAndAgeNotZero will be used. Your Eclipse error Invalid derived query should also disappear without need of disabling validation as described by @Tuan Dang

Checked on Eclipse 4.5.1 with Spring plugin installed for @NamedQuery and @NamedNativeQuery.

Tarrance answered 1/2, 2016 at 11:56 Comment(1)
Pawel Deleba, java.lang.IllegalArgumentException: query source string cannot be null or empty . your solution will not workToxic
B
0

I've just been going through this myself. Unfortunately, the implementation of Spring Data changed between 1.1 and 1.2. It no longer supports the <repository> XML declaration. You can set up a custom postfix, but by default, it expects a bean of class name <InterfaceName>Impl. If it can't find the custom repository implementation, you start getting errors like the one you're encountering. It's trying to create methods to query for objects based on names of methods in your interface.

An alternative is to back your Spring Data version down to 1.1 and specify a schemalocation of http://www.springframework.org/schema/data/jpa/spring-jpa-1.1.xsd in your XML.

Brownedoff answered 3/1, 2013 at 2:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.