Issue
I'm trying to create a basic repository so I can get my region's time zones as supported by Postgres. I'm getting the error "annotation type not applicable to this kind of declaration." How should I approach this? Why am I not allowed to define a query here?
import com.me.model.PgTz;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
@Repository
public interface TzRepository extends org.springframework.data.repository.Repository<PgTz,String>
{
@Query("SELECT tz FROM PgTz tz WHERE tz.name STARTSWITH 'US/' OR tz.name STARTSWITH 'America/'");
Iterable<PgTz> findPgTzByName();
}
Solution
The issue is due to a semicolon after @Query()
declaration which is illegal in java. Removing it should fix compilation.
@Query("SELECT tz FROM PgTz i WHERE i.name STARTSWITH('US/') OR i.name STARTSWITH('America/')")
Iterable<PgTz> findPgTzByName();
Answered By - Vitalii Vitrenko
Answer Checked By - Candace Johnson (JavaFixing Volunteer)