1
votes

Here is my model:

@Entity(name = "checkinusers")
public class User {

    @Id
    @JsonIgnore
    @ApiModelProperty(hidden = true)
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", nullable = false, columnDefinition = "INT(1)")
    private long userId;

    @Column(name = "username", nullable = false)
    private String username;

    @Column(name = "password", nullable = false, columnDefinition = "TEXT")
    private String password;

    @Column(name = "salt", nullable = false, columnDefinition = "TEXT")
    private String salt;

    @ApiModelProperty(hidden = true)
    @Column(name = "lastlogin", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    private Date created;

Here is the method:

@Modifying
@Transactional
@Query("UPDATE User u SET  u.created ='0000-00-00 00:00:00' WHERE u.username = :username ")
 void updateLastLogin(@Param("username") String username);

This is the error I get when I try to start spring application

Failed to execute goal
org.springframework.boot:spring-boot-maven-plugin:1.5.9.RELEASE:run(default-cli) on project licenta: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract void com.example.licenta.service.UserService.update(java.lang.String)! org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [UPDATE User u SET u.created ='0000-00-00 00:00:00' WHERE u.username = :user name ]

1

1 Answers

0
votes

The actual problem seems to be that JPA doesn't know the User entity:

org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped

As you specify a dedicated name in the @Entity annotation you need to use this name in all JPA queries on this entity:

@Entity(name = "checkinusers")

That is the query will need to be:

@Query("UPDATE checkinusers u SET  u.created = '0000-00-00 00:00:00' WHERE u.username = :username ")

See this question for details.