我想讓表位于不同的數據庫模式中。但不幸的是,我無法通過 Spring Boot 實現這一點。這是重現它的步驟。在http://start.spring.io版本 2.0.5上創(chuàng)建一個新的 Spring Boot 項目(帶有 derby 和 PostgreSQL 依賴項)創(chuàng)建簡單實體@Entity@Table(name = "my_table")public class MyTable { @Id Integer id;}僅將下一個屬性添加到 application.properties 的值為“update”或“create”(如果您嘗試“create-drop”,則會在此處描述另一個錯誤:https : //github.com/spring-projects/spring-boot /issues/7706#issuecomment-268798059)?,F在默認使用 Derby 數據源。spring.jpa.hibernate.ddl-auto=create運行生成的測試或主類。確保一切正常。修改實體,schema為@Table注解添加屬性?,F在實體看起來像:@Entity@Table(name = "my_table", schema = "my_schema")public class MyTable { @Id Integer id;}運行測試(或主類)。這次我在 Spring Boot 初始化過程中出現錯誤“ java.sql.SQLSyntaxErrorException: Schema 'MY_SCHEMA' does not exist”:完整日志列表可在此處獲得:https : //gist.github.com/asaushkin/8d767c92b2e7025dd359f7be43eefdd6檢查 PostgreSQL。此錯誤也會在 PostgreSQL 實例上重現。如果沒有 'schema' 屬性,Spring Boot 應用程序運行得很好,但是一旦這個屬性出現在 @Table 注釋上,就會拋出異常。完整日志在這里:https : //gist.github.com/asaushkin/dd0d677964556bf943c4f013d4785372我的問題是:為什么模式不是由 Spring Boot 創(chuàng)建的?這些選項也不能解決這個問題:spring.jpa.properties.javax.persistence.schema-generation.create-database-schemas=truespring.jpa.properties.hibernate.hbm2dll.create_namespaces=true鏈接https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html#configurations-hbmddlhttps://docs.spring.io/spring-boot/docs/current/reference/html/howto-data-access.html#howto-configure-jpa-properties更新(2019 年 3 月 11 日):我剛剛檢查了問題的當前行為。我想知道,但目前使用 Derby 驅動程序一切正常,并且該表是使用指定的架構創(chuàng)建的。但是在 PostgreSQL 中,錯誤仍然存在。生成的 SQL(用于 PostgreSQL)是:create table my_schema.my_table (id int4 not null, primary key (id))
添加回答
舉報
0/150
提交
取消