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
In my case, I accidentally typed ";" at the end of @Query. Might help someone else.
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
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