0
votes

I have a User class into my db, and in my java class:
User

@Entity
public class User extends Model{

    @Id
    @GeneratedValue
    public int id;  
    public String name; 
    public String username; 
    public String email; 
    public String password; 
    public String phoneNumber; 
    public Timestamp inscriptionDate;

    public static Finder<String,User> find = new Finder<String,User>(
                String.class, User.class
    ); 
}

And I try to retrieve the unique user based on its username using this Ebean statement :

User current = Ebean.find(User.class).where().eq("user.username", username).findUnique(); 

But I obtain this error:

Query threw SQLException:Column "USER.USERNAME" not found;

Why?

Here is the result of a Select query. (I deleted the value of the fields, but there are some values in it). Select * from user

1
did you try username instead of user.username? - sgpalit
I just did. It worked. Why? - Mornor
find(User.class) this is the table name where it will search. So you do not need again to give the table name. - sgpalit

1 Answers

1
votes

Your query is incorrect. It should be:

User current = Ebean.find(User.class).where().eq("username", username).findUnique();

This is because your entity class User represents the table USER. and the field username represents the column USERNAME.

In your query, the SQL engine is looking for the column USER.USERNAME in the USER table, hence the error. Changing the query to above will search the USERNAME column (which does exist) in the USER table.