【发布时间】:2018-01-30 11:26:10
【问题描述】:
我的 webapp 的 postgresql 数据库的休眠模式生成存在问题,该 webapp 托管在外部 tomcat (8.5.20) 中。
为此,我在我的 Spring Boot 应用程序中将 spring.jpa.hibernate.ddl-auto 设置为 create-drop。
当我使用嵌入式 tomcat 在我的 Eclipse 中运行应用程序时,所有 LocalDateTime 列都生成为
timestamp without time zone 这很好。
但是当生成war文件并部署到激活模式生成的外部tomcat时,所有这些列都生成为类型
bytea.
我试图定义在 context.xml 中链接的全局 jndi 资源 (server.xml),只有基于 context.xml 的 jndi 资源和 spring.data 和 spring.jpa 配置,当我在我的应用程序中运行 eclipse 时。特性。但是,一旦我将生成的战争部署到我的外部 tomcat,这些列就会生成为 bytea。
我也把postgresql-42.1.1.jar放到tomcat的lib文件夹下也没有成功。
这些是我对本地环境的设置,可以正常工作:
spring.datasource.url= jdbc:postgresql://localhost:5432/test
spring.datasource.username=postgres
spring.datasource.password=postgres
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.ddl-auto=create-drop
这是在 context.xml 中定义 tomcat jndi 数据源的示例,它生成 bytea 列:
<Resource name="jdbc/test" auth="Container"
type="javax.sql.DataSource" maxActive="20" maxIdle="5" maxWait="10000"
username="postgres" password="postgres" driverClassName="org.postgresql.Driver"
url="jdbc:postgresql://localhost:5432/test">
</Resource>
在这种情况下,我的应用程序属性如下所示:
spring.datasource.jndi-name=java:comp/env/jdbc/test
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.current_session_context_class=org.springframework.orm.hibernate5.SpringSessionContext
spring.jpa.hibernate.use-new-id-generator-mappings=true
spring.jpa.hibernate.ddl-auto=create-drop
我最后尝试的是构建并运行生成的 jar。再次生成类型为“bytea”的列。因此,将列生成为时区的唯一变体是在 eclipse 中运行应用程序...
有人有想法吗?
【问题讨论】:
标签: postgresql hibernate tomcat jpa spring-boot