Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotations are not allowed here

Tags:

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

like image 515
Andrey-2310 Avatar asked Aug 05 '17 21:08

Andrey-2310


2 Answers

In my case, I accidentally typed ";" at the end of @Query. Might help someone else.

like image 174
Lukenzo Avatar answered Sep 30 '22 18:09

Lukenzo


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

like image 41
Andrey-2310 Avatar answered Sep 30 '22 18:09

Andrey-2310