簡體   English   中英

如何正確讀取此異常? 這是休眠映射問題嗎?

[英]How correctly read this exception? Is it an Hibernate mapping issue?

我已經開始使用由另一個人啟動的 Hibernate 應用程序處理新的 Spring Boot,但我遇到以下問題:在應用程序啟動期間,我收到以下錯誤:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'placeSearcherController': Unsatisfied dependency expressed through field 'mainSearchServices'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainSearchServicesImpl': Unsatisfied dependency expressed through field 'accomodationDAO'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accomodationDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/betrivius/config/DatabaseConfig.class]: Invocation of init method failed; 
nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [id] in table [accomodation]; found [bigint (Types#BIGINT)], but expecting [integer (Types#INTEGER)]

所以,這個異常鏈的最后一個 exacption 是:

nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [id] in table [accomodation]; found [bigint (Types#BIGINT)], but expecting [integer (Types#INTEGER)]

我認為這僅意味着在數據庫表上我有一個BigInt值用於住宿表的id列,但在映射此表的住宿類上我有:

@Entity
@Table(name = "accomodation")
public class Accomodation implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    ..........................................................
    ..........................................................
    ..........................................................
}

這是問題嗎? 那么,MySql BigInt數據類型的正確 Java 類型是什么? 在線閱讀我發現 somoene 使用Long而其他人使用BigInteger 什么是最好的選擇?

另一個重要的疑問與如何正確讀取前面的異常鏈有關:

它首先在placeSearcherController bean 中顯示一個錯誤(它被拋出一個UnsatisfiedDependencyException )。

據我所知,這意味着placeSearcherController bean 中的錯誤取決於拋出到mainSearchServicesImpl bean(由placeSearcherController 使用)中的相同異常,依此類推,直到第一個拋出此異常的地方,即AccomodationDAOImpl實例(執行查詢的地方)。

這個解釋正確嗎?

我發現 somoene 使用 Long 而其他人使用 BigInteger。 什么是最好的選擇?

比較它們並根據您的需求做出決定。 對於大多數情況,Long 就足夠了,但不是全部。 這個問題的答案很有幫助:Long vs BigInteger

據我所知,這意味着 placeSearcherController bean 中的錯誤取決於拋出到 mainSearchServicesImpl bean(由 placeSearcherController 使用)中的相同異常,依此類推,直到第一個拋出此異常的地方,即 AccomodationDAOImpl 實例(執行查詢的地方)。

這個解釋正確嗎?

是的,雖然它本身不是查詢。 Hibernate 正在驗證它可以與現有的 db 模式一起工作,但發現它不能。

我遇到了這個問題,原因是實體的主鍵是原始類型。 通過將其更改為包裝器,我的問題解決了。

@Id
private Integer userId;

我遇到了同樣的問題。 請嘗試定義@ColumnDefinition

您可以獲取此錯誤的完整詳細信息 -> HERE

示例:

為表。

CREATE TABLE event (
    id NUMERIC(19,0) IDENTITY NOT NULL, 
    PRIMARY KEY (id)
)

實體會。

@Id
@GeneratedValue(
    strategy = GenerationType.IDENTITY
)
@Column(
    columnDefinition = "NUMERIC(19,0)"
)
private Long id;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM