嘗試使用 JPA 執行請求時出錯。
我在我的類物體中指定了表所在的架構:
@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(schema = "dwp_schema")
public class Corridor {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id_corridor;
private Integer id_floor;
private String orientation;
}
當我在我的存盤庫中執行特定請求時:
public interface CorridorRepository extends JpaRepository<Corridor, Integer> {
@Query(value = "select * from corridor c inner join floor f on f.id_floor=c.id_floor INNER JOIN building b on f.id_building = b.id_building WHERE b.building_name=?1 AND f.floor_number=?2" ,nativeQuery = true)
List<Corridor> getCorridorsByFloor(String building_name, int floor);
}
我在 Postgres 中有以下錯誤:
org.postgresql.util.PSQLException: ERROR: relation "corridor" does not exist
有人有想法嗎?
謝謝你。
uj5u.com熱心網友回復:
嘗試在表名之前寫模式名:
@Query(value = "select * from dwp_schema.corridor c inner join floor f on f.id_floor=c.id_floor INNER JOIN building b on f.id_building = b.id_building WHERE b.building_name=?1 AND f.floor_number=?2" ,nativeQuery = true)
uj5u.com熱心網友回復:
您需要在連接字串中指定您的資料庫和架構:
jdbc:postgresql://localhost:5432/dbname?currentSchema=dwp_schema
無論如何,將架構名稱放在物體宣告中都是一個壞主意 - 您的 DBA 應該能夠決定架構名稱。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/391475.html
標籤:爪哇 春天 PostgreSQL的 弹簧数据-jpa
上一篇:根據特定列洗掉重復行
