Annotations are not allowed here
Solution 1
In my case, I accidentally typed ";" at the end of @Query. Might help someone else.
Solution 2
Sorry, guys. It was so stupid for me to write double quotes in the end of this line. But I actually don't understand why Intellij didn't notice that but started to mark this line with another mistake
Solution 3
Sorry this was 4 years too late, but you have an extra ')' at the end of your @Query line
Solution 4
In my case, I accidently typed an ';' at the end of the @Query sentence.
@Query("SELECT a FROM Author a")
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value= "" + Integer.MIN_VALUE));
Stream<Author> streamAll();
After I removed the ';' from the @QueryHints, then it worked perfectly.
@Query("SELECT a FROM Author a")
@QueryHints(value = @QueryHint(name = HINT_FETCH_SIZE, value= "" + Integer.MIN_VALUE))
Stream<Author> streamAll();
Related videos on Youtube

Andrey-2310
Updated on December 17, 2021Comments
-
Andrey-2310 12 months
I'm creating a UserRepository which implements JpaRepository and works with User entity. I need a method to update username. I decided to do it with the help of @Query. But it's marked by Intellij. Here is my code for repository:
@Repository public interface UserRepository extends JpaRepository<User, Long> { @Modifying @Query(value = "update User user set user.name= %?username")) void updatingUser(@Param(value = "username") String username); }
And for Entity:
@Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "user_id") private Long id; @NotNull @Column(name = "user_name") private String username; }
And I faced with such a problem: "Annotations are not allowed here" says Intellij Idea and marks the line with @Query annotation. And it made me confused
-
Cepr0 over 5 yearsDon't forget to accept/upvote the answer if it helped you..
-
-
Andrey-2310 over 5 yearsThanks, I've corrected it. Now my query looks like this. Modifying Query(value = "update com.ranv.Model.ModelDB.User u set u.username = ?1 where u.id = ?2") void updatingUser( String username, Long id); Butnow there is the other problem: class User is not an Entity. But actually it is (Entity annotation is on it's place as you can see in my code above)
-
Cepr0 over 5 years@Andrey-2310 Check imports. I think you set a wrong one. (And don't forget that 'thanks' here is equal to 'accept/upvote the answer'..)
-
Andrey-2310 over 5 yearsbut this object is exactly what I need. It represents my entity.
-
Cepr0 over 5 yearsOk. I've answered on your first question?
-
Andrey-2310 over 5 years@ Cepr0, Yeah, sure. by the way the answer on my second question is adding Hibernate and JPA modules
-
Rajan Chauhan over 2 yearsi made the same mistake, removed ; and now code compiled successfully.
-
jkerak over 2 yearsfor me it was forgetting to add () to my method signature
-
Lucy about 2 yearsThanks for this answer. I had the same mistake, a semicolon at the end of line just out of habit.
-
Literate Corvette over 1 yearGlad I came here because that was gonna confuse me for a while. Love coming to stack overflow to find out I'm just regular dumb and not even complicated dumb.