5

I am trying to generate schema tables based on entities. But tables are not created. What's wrong?

Entity example:

@Entity
@NoArgsConstructor
@Getter @Setter
public class User {
    @Id @GeneratedValue(strategy = GenerationType.AUTO)
    public Long id;

    public String username;
    public String password;

    public User(String username, String password) {
        this.username = username;
        this.password = password;
    }

    public User(String username) {
        this(username, username + "pass");
    }
}

application.properties:

spring.datasource.url=jdbc:postgresql://localhost:5432/dbtest
spring.datasource.username=vssekorin
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto=update

Dependencies:

compile('org.springframework.boot:spring-boot-starter-data-jpa')
runtime('com.h2database:h2')
compile('org.telegram:telegrambots:3.6.1')
runtime('org.postgresql:postgresql')
compileOnly('org.projectlombok:lombok')
testCompile('org.springframework.boot:spring-boot-starter-test')

Warning: GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement

1
  • can you show the complete log for this "GenerationTarget encountered exception accepting command : Error executing DDL via JDBC Statement" Commented Jul 11, 2018 at 15:30

6 Answers 6

15

It should be:

spring.jpa.generate-ddl = true

in your application.properties.

Or you can change this line:

spring.jpa.hibernate.ddl-auto=update

in

spring.jpa.hibernate.ddl-auto=create

More details: Spring Database initialization

Sign up to request clarification or add additional context in comments.

Comments

2

just change spring.jpa.hibernate.ddl-auto from update to create.

Comments

0

Try adding this property spring.datasource.driverClassName=org.postgresql.Driver

and change spring.jpa.hibernate.ddl-auto from update to create

1 Comment

Hi @Aziz - welcome to Stack Overflow. Your answer more than 2.5 years after an answer was provided that accepted by the author of the OP (original post) doesn't seem to add anything new, OR you believe it does, then please edit the accepted answer to add your new insight.
0

Entity(name="Users") postgresql can't create a table named user and

spring.jpa.hibernate.ddl-auto=create

1 Comment

Thanks! I had spring.jpa.hibernate.ddl-auto = create-drop. Changing entity from 'User' to 'Users' did the trick for me.
0

In my case, i created a entities package outside the main application class;

Exemple:

wrong

enter image description here

correct

enter image description here

Comments

0

i have encountered same problem, in my case it was the fact i created the package model outside of the root folder where Application.java class is situated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.