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:
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
Post a Comment