错误信息如下:

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed;
 nested exception is org.hibernate.MappingException: could not instantiate id generator [entity-name=com.bean.CompanyNews]

通过错误信息提示可大概知道是【com.bean.CompanyNews】此文件无法实例化id生成器,然后打开此文件如下图所示

could not instantiate id generator_注解

因为此(ssh)项目之前原本连接的为oracle数据库,现在需要更改连接mysql数据库,因为数据库更换基本可以定位是主键生成策略的问题。将SEQUENCE修改为IDENTITY即可

备注:

@GeneratedValue 用于标注主键的生成策略,通过strategy 属性指定。默认情况下,JPA 自动选择一个最适合底层数据库的主键生成策略:Oracle对应SEQUENCE
在javax.persistence.GenerationType中定义了以下几种可供选择的策略: 
–IDENTITY:主键由数据库生成, 采用数据库自增长, Oracle不支持这种方式
–AUTO: JPA自动选择合适的策略,是默认选项; 
–SEQUENCE:通过数据库的序列产生主键,MySql不支持这种方式 
–TABLE:通过表产生主键,框架借由表模拟序列产生主键,使用该策略可以使应用更易于数据库移植。