I cannot create any table or column in PostgreSQL with springboot and there’s no exception observed. It’s driving me crazy. I really need your help. here is my code.
This is the model class
@Entity
@Data
@AllArgsConstructor
@Table(name = "doctor_info")
public class DoctorInfo {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column
private String fullName;
@Column
private String department;
@Column
private String userName;
@Column
private String password;
} ```
This is application properties
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql = true
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.datasource.url=jdbc:postgresql://localhost:5432/hospital
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.username=postgres
spring.datasource.password=root
spring.datasource.initialization-mode=always
spring.datasource.initialize=true
[this is the database I created][1]
[1]: https://i.stack.imgur.com/1Mvqa.png
2
Answers
You appear to have set up your Spring Boot application to operate with PostgreSQL correctly, but you’re having trouble adding tables or columns despite not running into any obvious exceptions or failures. Take into account the following procedures to resolve this problem:
Even if there are no obvious exceptions, you should first carefully review your console output. Insights can occasionally be gained from subtle error messages or warnings. Check to see if Spring Boot is correctly scanning your entity package and that it is either in the same package as or a subpackage of your main application class. Additionally, make sure to double-check your logs for SQL statements created by Hibernate at startup.
To avoid conflicts that could arise from cached class issues, clear the build and rebuild the application. Consult the documentation for each product to determine the recommended compatibility between the Spring Boot, Hibernate, and PostgreSQL driver versions.
Check that the Maven or Gradle dependencies you’re using are current and correctly synchronised with the PostgreSQL library version you’re using. Make sure the specified
hospital
database’s designated PostgreSQL user,postgres
, has the necessary rights to create tables.Try to make a streamlined entity class with just a few characteristics, like
id
, and a single field, likename
, as a diagnostic step. If it works, it might be able to identify the root of the issue. If you’ve tried these procedures and the problem still isn’t fixed, send any relevant logs or error messages for more precise troubleshooting.Why don’t you try something like Liquibase ( database schema change management)?
with that it’s also easier to maintain your db.
For that you have to add the dependency:
and organize your db changes in changelog files, like described in here:
https://www.baeldung.com/liquibase-refactor-schema-of-java-app