New to Spring ..
Trying to use the @Query annotation but get a message of: The annotation @Query is disallowed for this location
Got to be some setup or configuration I am missing here is what I have:
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/>
</parent>
… to dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
Compelled to use 1.5.2.RELEASE as it is the employer's current standard Looking in the Maven dependences I see: hibernate-core-5.0.12.Final hibernate-jpa-2.1-api-1.0.0.Final.jar spring-data-jpa-1.11.1.RELEASE.jar + many others
in some of the examples I have seen it seems like a easy matter to add the @Query annotation however it does not seem to work. currently I have just a entity, repo, controller and a main.
I have tried the @Repository but it does not seem to make a difference
here's the repo
public interface DeptRepo extends JpaRepository<Dept, Long> {
@Query(value = "select d from dept d where name = 'ACCOUNTING'")
List<Dept> findByAccounting;
}
application properties
spring.jpa.show_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle12cDialect
spring.datasource.url=jdbc:oracle:thin:@localhost:1521/to2b
spring.datasource.username=scott
spring.datasource.password=tiger
My question is what is the setup info I am missing?
Instead of
public interface DeptRepo extends JpaRepository<Dept, Long> {
@Query(value = "select d from dept d where name = 'ACCOUNTING'")
List<Dept> findByAccounting;
}
Use
public interface DeptRepo extends JpaRepository<Dept, Long> {
@Query(value = "select d from dept d where name = 'ACCOUNTING'")
List<Dept> findByAccounting();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With