I have an application that I\'m using spring boot and postgres. I\'m getting this error when I try to create a user.
When I run this query on my database, I get the
Give schema name also along with table name. It solved the issue for me.
@Entity
@Table(name = "APP_USER",schema="xxxxx")
public class User implements Serializable {
private static final long serialVersionUID = -1152779434213289790L;
@Id
@Column(name="ID", nullable = false, updatable = false)
@GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@Column(name="NAME", nullable = false)
private String name;
@Column(name="USER_NAME", nullable = false, unique = true)
private String username;
@Column(name="PASSWORD", nullable = false)
private String password;
@Column(name="EMAIL", nullable = false, unique = true)
private String email;
@Column(name="ROLE", nullable = false)
private RoleEnum role;
It might be also caused missing default schema
declaration in hibernate config.
Properties jpaProperties = new Properties();
..
jpaProperties.put("hibernate.default_schema", "my_default_schema");
entityManagerFactoryBean.setJpaProperties(jpaProperties);
You should check permissions from your app database login to your scheme.
There were not permissions to my scheme and I had the same problem.
PostgreSQL is following the SQL standard and in that case that means that identifiers (table names, column names, etc) are forced to lowercase, except when they are quoted. So when you create a table like this:
CREATE TABLE APP_USER ...
you actually get a table app_user
. You apparently did:
CREATE TABLE "APP_USER" ...
and then you get a table "APP_USER"
.
In Spring, you specify a regular string for the table name, in capital letters, but that gets spliced into a query to the PostgreSQL server without quotes. You can check this by reading the PostgreSQL log files: it should show the query that Spring generated followed by the error at the top of your message.
Since you have very little control over how Spring constructs queries from entities, you are better off using SQL-standard lower-case identifiers.
This could also happen if your mapping file is not defined properly in jpa configuration file. In my case, there was a new line character before (end tag where mapping file is defined) in jpa configuration.