title: getting the current logged in user in JHipster
body: <p>I am building a jhipster application. and I am trying to get a list of objects based on the current logged in user. there are a few simple examples online such as <a href="https://github.com/mraible/jhipster4-demo/blob/master/src/main/java/org/jhipster/domain/Blog.java" rel="nofollow noreferrer">jhipster blog demo</a> that describe how to get the current user's blogs by the current logged in user--and I wanted to mimic this. in the demo there isa repo method:</p>
  
  <pre><code>@Query("select blog from Blog blog where blog.user.login = ?#{principal.username}")
  List&lt;Blog&gt; findByUserIsCurrentUser();
  </code></pre>
  
  <p>I have tried to mimic this with the following:</p>
  
  <pre><code>@Query("select userWorkoutTemplate from WorkoutTemplate workoutTemplate where workoutTemplate.userDemographic.user.login = ?#{principal.username}")
  List&lt;WorkoutTemplateDTO&gt; findByUserIsCurrentUser();
  </code></pre>
  
  <p>but my IDE throws this error:</p>
  
  <blockquote>
    <p>nested exception is java.lang.IllegalArgumentException: Validation failed for query for method public abstract java.util.List com.thefitnation.repository.WorkoutTemplateRepository.findByUserIsCurrentUser()!</p>
  </blockquote>
  
  <p>I am not too familiar with hibernate queries, but the parameter seems to be in error in my IDE. Does the parameter on the end need to be configured somewhere? I am using plain jhipster 4 out of the box with DTO objects. </p>
  
  <p>here are the relevant entities:</p>
  
  <p>User.java</p>
  
  <pre><code>@Entity
  @Table(name = "jhi_user")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class User extends AbstractAuditingEntity implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
  @SequenceGenerator(name = "sequenceGenerator")
  private Long id;
  
  @NotNull
  @Pattern(regexp = Constants.LOGIN_REGEX)
  @Size(min = 1, max = 50)
  @Column(length = 50, unique = true, nullable = false)
  private String login;
  
  @JsonIgnore
  @NotNull
  @Size(min = 60, max = 60)
  @Column(name = "password_hash",length = 60)
  private String password;
  
  @Size(max = 50)
  @Column(name = "first_name", length = 50)
  private String firstName;
  
  @Size(max = 50)
  @Column(name = "last_name", length = 50)
  private String lastName;
  
  @Email
  @Size(max = 100)
  @Column(length = 100, unique = true)
  private String email;
  
  @NotNull
  @Column(nullable = false)
  private boolean activated = false;
  
  @Size(min = 2, max = 5)
  @Column(name = "lang_key", length = 5)
  private String langKey;
  
  @Size(max = 256)
  @Column(name = "image_url", length = 256)
  private String imageUrl;
  
  @Size(max = 20)
  @Column(name = "activation_key", length = 20)
  @JsonIgnore
  private String activationKey;
  
  @Size(max = 20)
  @Column(name = "reset_key", length = 20)
  private String resetKey;
  
  @Column(name = "reset_date")
  private ZonedDateTime resetDate = null;
  
  @JsonIgnore
  @ManyToMany
  @JoinTable(
      name = "jhi_user_authority",
      joinColumns = {@JoinColumn(name = "user_id", referencedColumnName = "id")},
      inverseJoinColumns = {@JoinColumn(name = "authority_name", referencedColumnName = "name")})
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  @BatchSize(size = 20)
  private Set&lt;Authority&gt; authorities = new HashSet&lt;&gt;();
  ....
  </code></pre>
  
  <p>UserDemographic.java</p>
  
  <pre><code>@Entity
  @Table(name = "user_demographic")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class UserDemographic implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
  @SequenceGenerator(name = "sequenceGenerator")
  private Long id;
  
  @NotNull
  @Column(name = "created_on", nullable = false)
  private LocalDate createdOn;
  
  @NotNull
  @Column(name = "last_login", nullable = false)
  private LocalDate lastLogin;
  
  @Enumerated(EnumType.STRING)
  @Column(name = "gender")
  private Gender gender;
  
  @NotNull
  @Column(name = "date_of_birth", nullable = false)
  private LocalDate dateOfBirth;
  
  @Column(name = "height")
  private Float height;
  
  @NotNull
  @Enumerated(EnumType.STRING)
  @Column(name = "unit_of_measure", nullable = false)
  private UnitOfMeasure unitOfMeasure;
  
  @OneToOne(optional = false)
  @NotNull
  @JoinColumn(unique = true)
  private User user;
  
  @ManyToMany
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  @JoinTable(name = "user_demographic_gym",
             joinColumns = @JoinColumn(name="user_demographics_id", referencedColumnName="id"),
             inverseJoinColumns = @JoinColumn(name="gyms_id", referencedColumnName="id"))
  private Set&lt;Gym&gt; gyms = new HashSet&lt;&gt;();
  
  @OneToMany(mappedBy = "userDemographic")
  @JsonIgnore
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  private Set&lt;UserWeight&gt; userWeights = new HashSet&lt;&gt;();
  
  @OneToMany(mappedBy = "userDemographic")
  @JsonIgnore
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  private Set&lt;WorkoutTemplate&gt; workoutTemplates = new HashSet&lt;&gt;();
  
  @OneToMany(mappedBy = "userDemographic")
  @JsonIgnore
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  private Set&lt;UserWorkoutTemplate&gt; userWorkoutTemplates = new HashSet&lt;&gt;();
  
  @ManyToOne(optional = false)
  @NotNull
  private SkillLevel skillLevel;
  </code></pre>
  
  <p>UserWorkoutTemplate.java</p>
  
  <pre><code>@Entity
  @Table(name = "user_workout_template")
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  public class UserWorkoutTemplate implements Serializable {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
  @SequenceGenerator(name = "sequenceGenerator")
  private Long id;
  
  @NotNull
  @Column(name = "created_on", nullable = false)
  private LocalDate createdOn;
  
  @NotNull
  @Column(name = "last_updated", nullable = false)
  private LocalDate lastUpdated;
  
  @Column(name = "notes")
  private String notes;
  
  @ManyToOne(optional = false)
  @NotNull
  private UserDemographic userDemographic;
  
  @ManyToOne
  private WorkoutTemplate workoutTemplate;
  
  @OneToMany(mappedBy = "userWorkoutTemplate", fetch = FetchType.EAGER)
  @JsonIgnore
  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  private Set&lt;UserWorkoutInstance&gt; userWorkoutInstances = new HashSet&lt;&gt;();
  </code></pre>