gpt4 book ai didi

java - 如何正确读取这个异常?这是 Hibernate 映射问题吗?

转载 作者:行者123 更新时间:2023-12-01 18:02:00 25 4
gpt4 key购买 nike

我已经开始使用由另一个人启动的 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)]

因此,该异常链的最后一个异常(exception)是:

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)]

我认为这仅意味着在数据库表中,accomodation 表的 id 列有一个 BigInt 值,但在映射此表的 Accomodation 类:

@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 中的错误取决于抛出到 ma​​inSearchServicesImpl bean 中的相同异常(由 placeSearcherController 使用) )等等,直到到达第一个抛出此异常的地方,即 AccomodationDAOImpl 实例(执行查询的地方)。

这个解释正确吗?

最佳答案

I fount that somoene use Long and someone else use BigInteger. What is the best choice?

比较它们并根据您的需求做出决定。对于大多数情况,长就足够了,但不是全部。这个问题的答案很有帮助:Long vs BigInteger

From what I have understand it means that the error into the placeSearcherController bean depends by the same exception that is thrown into the mainSearchServicesImpl bean (used by placeSearcherController) and so on untile came to the first place where this exception was thrown that is the AccomodationDAOImpl instance (where the query is performed).

Is this interpretation correct?

是的,尽管它本身不是查询。 Hibernate 正在验证它是否可以与现有的数据库模式一起工作,但发现它不能。

关于java - 如何正确读取这个异常?这是 Hibernate 映射问题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40221331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com