我已经尝试了所有发现的here,并在与搜索相关的所有Google匹配项中进行了尝试。我被这个问题困扰了2天了,首先我认为问题可能出在MySQL上,所以尝试了Postgres,但还是没有。 数据库与应用程序连接,当我创建一个新表时,我可以在Postgres中看到它,如果删除该表,它也会从Intellij中消失。 但是从实体中它什么也不会产生,甚至不会引发任何错误。
application.properties:
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres_demo
spring.datasource.username= postgres
spring.datasource.password=1234
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
spring.jpa.hibernate.ddl-auto = create
spring.jpa.generate-ddl = true
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
PostgresDemoApplication clsaa:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
@EnableJpaAuditing
@SpringBootApplication
@EntityScan(basePackages = "models")
public class PostgresDemoApplication {
public static void main(String[] args) {
SpringApplication.run(PostgresDemoApplication.class, args);
}
}
模型类:
import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
@Entity
@Table(name = "question")
public class Question extends AuditModel {
@Id
@GeneratedValue(generator = "question_generator")
@SequenceGenerator(
name = "question_generator",
sequenceName = "question_generator",
initialValue = 1000
)
private Long id;
@NotBlank
@Size(min = 3, max = 100)
private String title;
@Column(columnDefinition = "text")
private String description;
弹簧靴
2018-09-09 14:11:35.261 INFO 2140 --- [ restartedMain] c.i.p.PostgresDemoApplication : Starting PostgresDemoApplication on DESKTOP-5Q2LCCO with PID 2140 (D:\Isshae\Java\postgres-demo\out\production\classes started by asus in D:\Isshae\Java\postgres-demo)
2018-09-09 14:11:35.262 INFO 2140 --- [ restartedMain] c.i.p.PostgresDemoApplication : No active profile set, falling back to default profiles: default
2018-09-09 14:11:35.338 INFO 2140 --- [ restartedMain] ConfigServletWebServerApplicationContext : Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@44c035dd: startup date [Sun Sep 09 14:11:35 CEST 2018]; root of context hierarchy
2018-09-09 14:11:36.467 INFO 2140 --- [ restartedMain] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$41d31d19] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-09-09 14:11:36.908 INFO 2140 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http)
2018-09-09 14:11:36.925 INFO 2140 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2018-09-09 14:11:36.925 INFO 2140 --- [ restartedMain] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.5.32
2018-09-09 14:11:36.929 INFO 2140 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Users\asus\AppData\Local\Programs\Python\Python37-32\Scripts\;C:\Users\asus\AppData\Local\Programs\Python\Python37-32\;C:\Users\asus\AppData\Local\Microsoft\WindowsApps;;.]
2018-09-09 14:11:37.052 INFO 2140 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2018-09-09 14:11:37.052 INFO 2140 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1717 ms
2018-09-09 14:11:37.111 INFO 2140 --- [ost-startStop-1] o.s.b.w.servlet.ServletRegistrationBean : Servlet dispatcherServlet mapped to [/]
2018-09-09 14:11:37.111 INFO 2140 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2018-09-09 14:11:37.111 INFO 2140 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2018-09-09 14:11:37.111 INFO 2140 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2018-09-09 14:11:37.111 INFO 2140 --- [ost-startStop-1] o.s.b.w.servlet.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2018-09-09 14:11:37.242 INFO 2140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...
2018-09-09 14:11:37.498 INFO 2140 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed.
2018-09-09 14:11:37.534 INFO 2140 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2018-09-09 14:11:37.534 INFO 2140 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2018-09-09 14:11:37.675 INFO 2140 --- [ restartedMain] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2018-09-09 14:11:37.677 INFO 2140 --- [ restartedMain] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2018-09-09 14:11:37.707 INFO 2140 --- [ restartedMain] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2018-09-09 14:11:37.809 INFO 2140 --- [ restartedMain] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
2018-09-09 14:11:37.829 INFO 2140 --- [ restartedMain] o.h.e.j.e.i.LobCreatorBuilderImpl : HHH000422: Disabling contextual LOB creation as connection was null
2018-09-09 14:11:37.829 INFO 2140 --- [ restartedMain] org.hibernate.type.BasicTypeRegistry : HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@4ab9bbe7
2018-09-09 14:11:38.554 INFO 2140 --- [ restartedMain] o.h.t.schema.internal.SchemaCreatorImpl : HHH000476: Executing import script 'org.hibernate.tool.schema.internal.exec.ScriptSourceInputNonExistentImpl@7d8c0ef6'
2018-09-09 14:11:38.554 INFO 2140 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-09-09 14:11:38.724 INFO 2140 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-09 14:11:38.974 INFO 2140 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@44c035dd: startup date [Sun Sep 09 14:11:35 CEST 2018]; root of context hierarchy
2018-09-09 14:11:38.999 WARN 2140 --- [ restartedMain] aWebConfiguration$JpaWebMvcConfiguration : 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
2018-09-09 14:11:39.052 INFO 2140 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-09-09 14:11:39.053 INFO 2140 --- [ restartedMain] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-09-09 14:11:39.076 INFO 2140 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-09 14:11:39.076 INFO 2140 --- [ restartedMain] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-09-09 14:11:39.123 WARN 2140 --- [ restartedMain] ion$DefaultTemplateResolverConfiguration : Cannot find template location: classpath:/templates/ (please add some templates or check your Thymeleaf configuration)
2018-09-09 14:11:39.371 INFO 2140 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-09-09 14:11:39.394 INFO 2140 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-09-09 14:11:39.399 INFO 2140 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2018-09-09 14:11:39.403 INFO 2140 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2018-09-09 14:11:39.435 INFO 2140 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-09-09 14:11:39.436 INFO 2140 --- [ restartedMain] c.i.p.PostgresDemoApplication : Started PostgresDemoApplication in 4.503 seconds (JVM running for 5.399)