我對彈簧啓動非常陌生。看來我可以連接到Oracle數據庫但無法獲取數據。作爲一個新手,首先我已經嘗試了正確的憑據,沒有錯誤被拋出。另一方面,我改變了我的密碼,並得到無效的密碼錯誤。所以我認爲我的聯繫似乎是作出了?無法通過彈簧啓動從oracle獲取數據
我的全堆棧跟蹤可以在這裏找到:spring boot hibernate query invalid user error
當我從其他的帖子看到,春季以來列名轉換成駱駝命名策略可能是一個問題。雖然,在我的情況下,它似乎並不是一個問題,因爲我使用
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
它阻止彈簧更改列名稱。
這是我得到的查詢:
Hibernate: select * from (select post0_.id as id1_0_0_, user1_.id as id1_1_1_, post0_.author_id as author_id5_0_0_, post0_.body as body2_0_0_, post0_.date as date3_0_0_, post0_.title as title4_0_0_, user1_.fullName as fullName2_1_1_, user1_.passwordHash as passwordHash3_1_1_, user1_.username as username4_1_1_ from posts post0_ left outer join users user1_ on post0_.author_id=user1_.id order by post0_.date DESC) where rownum <= ?
而且它引發的異常:
java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification
我也曾嘗試使用本機,如下圖所示:
@Repository
public interface PostRepository extends JpaRepository<Post, Long> {
@Query(value = "SELECT * FROM POSTS aa JOIN USERS bb ON aa.AUTHOR_ID=bb.ID", nativeQuery = true)
List<Post> findLatest5Posts();}
這次沒有發生錯誤。但是,它不返回任何內容,爲空結果集。
那麼我該如何解決這個問題呢?
在此先感謝。
非常感謝@Nis!我已更改列名稱,它工作。另外,還有一些其他問題。例如。當創建POSTS表時我手動添加了外鍵,這是完全不必要的,因爲我已經通過我的代碼給出了鏈接。所以我有這個錯誤。總結一下,手動添加主鍵到表格和更改保留字在我的情況下工作。 –