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     }

  • 相关阅读:
    SpringBoot jar包不支持jsp
    Spring Boot 启动报错:LoggingFailureAnalysisReporter
    spring boot与spring mvc的区别是什么?
    解决配置JAVA_HOME JDK版本不变的问题
    Linux下修改Mysql的用户(root)的密码
    CentOS/Linux 解决 SSH 连接慢
    Linux查看进程的所有子进程和线程
    Linux命令之pstree
    使用awk批量杀进程的命令
    lucene 自定义评分
  • 原文地址:https://www.cnblogs.com/achievec/p/5595151.html
Copyright © 2011-2022 走看看