I am developing an application but my tables excpet one are not being created by JPA. I'm not able to fix the issue. I already went over some solution on stacks but they did not work. For the cases I checked, the issue was that no tables are being created. But for me, one table is being created.
Here is my packages in eclispe IDE:
All Entity classes are stored in the com.datcarts.datcartservices.model package.
My POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.datcarts</groupId>
<artifactId>datcartservices</artifactId>
<version>0.0.1</version>
<name>datcartservices</name>
<description>DatCarts</description>
<packaging>war</packaging>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-mapper-orm</artifactId>
<version>6.1.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-lucene</artifactId>
<version>6.1.1.Final</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber -->
<dependency>
<groupId>com.googlecode.libphonenumber</groupId>
<artifactId>libphonenumber</artifactId>
<version>8.12.46</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.vladmihalcea</groupId>
<artifactId>hibernate-types-55</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20211205</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.storilabs.security</groupId>
<artifactId>stori-sec</artifactId>
<version>1.0_Dev</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/com/storilabs/security/stori-sec/1.0_Dev/stori-sec-1.0_Dev.jar
</systemPath>
</dependency>
</dependencies>
<build>
<finalName>datcartservices</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And here is a sample Entity file:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.datcarts.datcartservices.model;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
/**
*
* @author najeeba
*/
@Entity
@Table(name="offer_details")
@Getter
@Setter
@ToString
@AllArgsConstructor
@NoArgsConstructor
public class OfferDetails extends DateAudit implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="offer_id")
private Long offerId;
public enum Status {
ACTIVE,
DISABLED,
}
private String page;
private String section;
private String imageUrl;
@NotNull
@Enumerated(EnumType.STRING)
private Status status;
@JoinColumn(name = "erp_id", referencedColumnName = "erp_id", nullable = false)
@ManyToOne(optional = false)
private ErpDetails erpDetails;
@Override
public int hashCode() {
int hash = 0;
hash = (offerId != null ? offerId.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof OfferDetails)) {
return false;
}
OfferDetails other = (OfferDetails) object;
if ((this.offerId == null && other.offerId != null) || (this.offerId != null && !this.offerId.equals(other.offerId))) {
return false;
}
return true;
}
}
The code deploys fine without errors (on Wildfly) but when I check postgres db, I see that only one table has been created:
And this is my application.properties file:
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.hibernate.ddl-auto = create
logging.level.org.hibernate.SQL= DEBUG
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.sql.init.mode=always
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS= false
spring.jackson.time-zone= UTC
spring.application.name=DatCart Services
spring.jpa.generate-ddl=true
# Database config
app.database.url= jdbc:postgresql://localhost:5432/newdats
app.database.username.key=
app.database.username.encrypted=datsuser
app.database.password.key=
app.database.password.encrypted=datspassword
Am I doing somethng wrong here?
Thank you for the responses!
CodePudding user response:
Try adding this property:
spring.jpa.generate-ddl=true
CodePudding user response:
spring.jpa.generate-ddl=true spring.jpa.hibernate.ddl-auto = create
try adding the above two in properties file also if that doesn't help add as spring.datasource.driverClassName=org.postgresql.Driver