1.异常:org.hibernate.AnnotationException: No identifier specified for entity异常。

entity类是必须要主键的,否则就会报出这个异常。
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    private Integer id;

2.异常:exception just for purpose of providing stack trace

count(*) 返回的结果为Long类型,而非Integer

 3.异常 org.hibernate.UnknownEntityTypeException

在使用spring的orm时,entity类没在hibernate sessionFactory的扫描中,导致。@entity要使用javax的entity而不是hibernate的。

 

    <bean id="sessionFactory" 
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan">
            <list>
                <!-- 可以加多个包 -->
                <value>com.test.common.entity</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>  
                <prop key="hibernate.format_sql">true</prop> 
            </props>
        </property>
    </bean>

4. org.hibernate.HibernateException: identifier of an instance of com.*.*DO was altered from 27 to null

出现这样的异常是从get中获取do对象,在进行更新前,将主键id给置为null导致。注意 BeanUtils.copyProperties,会将导入对象的null也给导入过来。

 5. org.hibernate.HibernateException:Multiple references to database, sequence  [**] were encountered attempting toset conflict values for initial value

出现的原因是在entity中有两个重复的实体类对应了sequence,多见于实体类重命名后mvn没有重新clean导致。  mvn clean package

6. spring-boot项目出错: 

Spring Boot  下使用JPA,报org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set错误

配置文件中没有指定hibernate.dialect:添加

spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect

posted on 2017-12-19 18:06  zhaoqiang1980  阅读(1618)  评论(0编辑  收藏  举报