• hibernate 异常


    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

  • 相关阅读:
    Lua基础之Function
    Lua基础之table详解
    Lua基础之语法
    详解C#中的反射(转载)
    Cocos-x 3.2:从C++过渡到Lua(转载)
    cocos2dx-Lua中出现的问题
    (转载)Cocos2dx-OpenGL ES2.0教程:纹理贴图(6)
    (转载)Cocos2dx-OpenGL ES2.0教程:你的第一个立方体(5)
    hdu 2098 分拆素数和(一个偶数拆分成两个不同素数和 拆法数量)
    51Nod
  • 原文地址:https://www.cnblogs.com/DennyZhao/p/7131962.html
Copyright © 2020-2023  润新知