I am new with Spring Boot, I know this is a repeated issue, but I have checked this QAs and nothing has helped me.
First Scenario
I was using jakarta as the @Entity
and @Table
annotations automatically imported it.
application.properties
spring.jpa.database=POSTGRESQL
spring.sql.init.platform=postgres
spring.datasource.url=jdbc:postgresql://localhost:5433/spring_boot
spring.datasource.username=postgres
spring.datasource.password=xxxxxx
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
logging.level.org.hibernate.SQL=DEBUG
A very simple class
Pais.java
package xyz.hector.persona.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
@Entity
@Table(name="pais", schema="public")
public class Pais {
public Pais(String nombre){
this.nombre = nombre;
}
public Pais() {
}
@Id
@GeneratedValue
private int id;
//getters and setters
}
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
The structure of the files is this one (I saw an issue this could be a problem so I follow the specifications I read).
Second sceneario
After some hours of reading and tears I and issue (I lost it) saying that this issue was very easy to solve by using javax. So, I did the following changes in my code.
Pais.java
package xyz.hector.persona.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name="pais", schema="public")
public class Pais {
public Pais(String nombre){
this.nombre = nombre;
}
public Pais() {
}
@Id
@GeneratedValue
private int id;
//getters and setters
}
aplication.properties
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.2.Final</version>
</dependency>
- I have tried changing
spring.jpa.hibernate.ddl-auto=update
tocreate
andcreate-drop
in both scenarios but this has been useless. - I have the database up and running.
- For every change to the
pom.xml
file I always reload the project.
Does anybody see what Im missing?