java - org.postgresql.util.PSQLException: ERROR: column user0_.id does not exist - Hibernate -


i have model class mapped postgres database using hibernate. model class is:

@entity @table(name="user") public class user {      @id      @generatedvalue     @column(name="id")     private long id;      @column(name="username", unique=true)     private string username;      @column(name="email")     private string email;      @column(name="created")     private timestamp created;      public user(long id, string username, string email) {         this.id = id;         this.username = username;         this.email = email;     } } 

i try retrieve user username "adam" using below query:

tx = session.begintransaction(); typedquery<user> query = session.createquery("from user u u.username = :username", user.class).setparameter("username", "adam"); user = query.getsingleresult(); 

i exception says:

org.postgresql.util.psqlexception: error: column user0_.id not exist 

my database bash shell looks like:

database

how hibernate map class attributes table columns? match based on @column(name="username") or try match based on datatypes , constraints such unique/auto-increment?

it gives error :

org.postgresql.util.psqlexception: error: column user0_.id not exist 

because when create database postgres dbms create default schema named public , when don't specify name in entity check in schema error, solve problem have specify name of schema :

@table(name="user", schema = "myapp") 

another thing confirm schema name not correct, error said :

column user0_.id not exist 

and not :

column myapp.user0_.id not exist -------^----^ 

which confirm query use public schema , not real schema myapp


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -