繁体   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