zoukankan      html  css  js  c++  java
  • 【06-17】开发中遇到的异常

    hibernate:


    bug:

      Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1

    solution:

      hibernate在执行save(Object obj)时,如果obj的主键不为空,则会去update而不是save操作,此时如果obj的主键不为空,但是在数据库中查不到时则会抛出该异常,因此save时可以显示将主键字段设为Null。

      也有可能是有级联关系的对象没有保存过,在save时

    bug:

      a different object with the same identifier value was already associated with the session

    solution:

      

    bug:

      identifier of an instance of ... is alterde from 150 to null

    solution:

      

    bug:

      org.hibernate.MappingException: Unknown entity

    solution:

      我用的是hibernate5,使用sessionFactory=new Configuration().configure().buildSessionFactory();能够获取到sessionFactory但是hibernate却找不到注解的实体类,抛出MappingException,使用以下方法才能够获取到注解类。

     1     public static SessionFactory sessionFactory;
     2     static{
     3 //        Configuration cfg= new Configuration();
     4 //        cfg.addClass(Person.class);
     5 //        cfg.addClass(Phone.class);
     6 //        cfg.addAnnotatedClass(entity.Person.class);
     7 //        cfg.addAnnotatedClass(entity.Phone.class);
     8 //        sessionFactory=new Configuration().configure().buildSessionFactory();
     9         final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
    10                 .configure() // configures settings from hibernate.cfg.xml
    11                 .build();
    12         try {
    13             sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    14         }
    15         catch (Exception e) {
    16             // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
    17             // so destroy it manually.
    18             StandardServiceRegistryBuilder.destroy( registry );
    19         }
    20         
    21     }

  • 相关阅读:
    filp_open/filp_close/vfs_read/vfs_write
    memcpy一种实现方法
    memset函数的实现&printf函数几种输出格式的输出结果
    break退出循环分析
    定义指针变量作为返回值函数执行时报 段错误(核心已转储)
    node实现防盗链
    js实现输入密码之延迟星号和点击按钮显示或隐藏
    rem适配
    使用字蛛教程以及遇到的bug
    es6学习笔记-proxy对象
  • 原文地址:https://www.cnblogs.com/achievec/p/5595151.html
Copyright © 2011-2022 走看看