【发布时间】:2017-03-06 09:39:56
【问题描述】:
我已经开始使用另一个人启动的 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)]
所以,这个异常链的最后一个例子是:
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 中的错误取决于 mainSearchServicesImpl bean 中抛出的相同异常(由 placeSearcherController 使用) 以此类推,直到抛出此异常的第一个位置,即 AccomodationDAOImpl 实例(执行查询的位置)。
这个解释正确吗?
【问题讨论】:
标签: java spring hibernate spring-boot spring-data