'Hibernate does not create table, in spite of connection and user roles are good
I'm facing an issue I can't even trace or see - it does not show any warning or fail message.
When I start my app, the postgresql database table is not created for the item I annotated as @Entity, and I just cannot find the issue. What I tried, based on several answers here for kind of similar problems:
- tried to do some changes in application.properties, but i really think that the problem is not here. The database connection is up, the user im using is superuser and created the table and I granted all roles for this table to this user to be sure.
- tried ScanEntities - with com.bentor.LastRevision and com.bentor and com.bentor.LastRevision.Document, no result.
- tried scanBasePackages() with the same things, no result.
- added an interface to have a method to get all items in the table and added a method to get them to the Controller class (I know, the table does not exist, but hey, getting an error would mean something happened in the database). I did this so I can see if even anything happens with my database. No result.
Help me please, I am clueless... After running the main:
2022-01-27 23:10:39.813 INFO 796 --- [ main] c.b.L.LastRevisionApplication : Starting LastRevisionApplication using Java 1.8.0_111 on DESKTOP-K96H2D9 with PID 796 (C:\Users\User\IdeaProjects\LastRevision\target\classes started by User in C:\Users\User\IdeaProjects\LastRevision)
2022-01-27 23:10:39.819 INFO 796 --- [ main] c.b.L.LastRevisionApplication : No active profile set, falling back to default profiles: default
2022-01-27 23:10:41.454 INFO 796 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2022-01-27 23:10:41.488 INFO 796 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 12 ms. Found 0 JPA repository interfaces.
2022-01-27 23:10:42.923 INFO 796 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2022-01-27 23:10:42.942 INFO 796 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-01-27 23:10:42.942 INFO 796 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-01-27 23:10:43.140 INFO 796 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-01-27 23:10:43.140 INFO 796 --- [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 3210 ms
2022-01-27 23:10:43.650 INFO 796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2022-01-27 23:10:44.436 INFO 796 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2022-01-27 23:10:44.532 INFO 796 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2022-01-27 23:10:44.681 INFO 796 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.6.4.Final
2022-01-27 23:10:45.132 INFO 796 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2022-01-27 23:10:45.390 INFO 796 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2022-01-27 23:10:46.298 INFO 796 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2022-01-27 23:10:46.316 INFO 796 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2022-01-27 23:10:46.407 WARN 796 --- [ main] JpaBaseConfiguration$JpaWebConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2022-01-27 23:10:47.042 INFO 796 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2022-01-27 23:10:47.061 INFO 796 --- [ main] c.b.L.LastRevisionApplication : Started LastRevisionApplication in 8.106 seconds (JVM running for 9.065)
My main class:
package com.bentor.LastRevision;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.bentor.LastRevision"})
public class LastRevisionApplication {
public static void main(String[] args) {
SpringApplication.run(LastRevisionApplication.class, args);
}
}
My Entity:
package com.bentor.LastRevision.Document;
import javax.persistence.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
@Entity
@Table(name = "document")
public class Document {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String docRef;
private String docName;
private String docRevision;
@ElementCollection
private Map<String, String> docDco = new HashMap<>();
private LocalDate dateOfPublish;
private String prodName;
private ArrayList<Integer> prodVersion;
public Document() {
}
public Document(String docRef, String docName, String docRevision,
String docDco, LocalDate dateOfPublish,
String prodName, String prodVersion) {
this.docRef = docRef;
this.docName = docName;
this.docRevision = docRevision;
this.dateOfPublish = dateOfPublish;
this.prodName = prodName;
this.docDco.put(docDco, docRef);
String[] listOfVersions = prodVersion.split("\\.");
this.prodVersion = new ArrayList<>(listOfVersions.length);
for (String s : listOfVersions) {
this.prodVersion.add(Integer.parseInt(s));
}
}
public Document(String docRef, String docName, String docDco,
String prodName, String prodVersion) {
this.docRef = docRef;
this.docName = docName;
this.docDco.put(docDco, docRef);
this.prodName = prodName;
String[] listOfVersions = prodVersion.split("\\.");
this.prodVersion = new ArrayList<>(listOfVersions.length);
for (String s : listOfVersions) {
this.prodVersion.add(Integer.parseInt(s));
}
}
- Getters, Setters, .equals(), .toString()
I hope anyone can help me with this. I am trying to learn Spring, but this issue had me today for 5 hours and counting.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
