我正在开发一个应用程序,但是JPA没有创建我的表(除了一个表)。我无法解决这个问题。我已经检查了一些关于堆栈的解决方案,但是它们不起作用。对于我检查的情况,问题是没有创建表。但是对我来说,创建了一个表。
下面是我在eclispe IDE中的软件包:
所有实体类都存储在com.datcarts.datcartservices.model包中。
我的POM文件:
<?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>
下面是一个示例实体文件:
/*
* 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;
}
}
代码部署得很好,没有错误(在Wildfly上),但是当我检查postgres db时,我看到只创建了一个表:
这是我的application.properties文件:
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
我做错什么了吗?
感谢您的回复!
2条答案
按热度按时间9gm1akwq1#
尝试添加此属性:
fsi0uk1n2#
jpa.jpa.jpa = jpa = jpa.jpa.jpa = jpa.
尝试在属性文件中添加以上两个,如果这样做没有帮助的话,也可以添加为spring.datasource.driverClassName = org.postgresql.Driver