• JPA 开发中遇到的错误


    常见异常 1、异常信息:org.hibernate.hql.ast.QuerySyntaxException: person is not mapped 异常环境:查询 异常原因:查询语句中Person类没有大写
    2、java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to java.lang.String 异常环境:查询、遍历显示 异常原因:转型出错
    3、javax.persistence.NonUniqueResultException: result returns more than one elements 异常环境:查询、getSingleResult 异常原因:getSingleResult只能获取一条数据,而查询语句返回的是多条数据
    4、 org.hibernate.PropertyValueException: not-null property references a null or transient value: com.sunyard.entities.Person.name 异常环境:数据插入 异常原因:JPA的Entity中一个属性定义为nullable=false,插入数据该字段为null
    5、 执行添加没反应、没异常 异常原因:没有开启事务、没有提交事务
    6、javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: com.sunyard.entities.Person 异常环境:OneToOne 共享主键关联 异常原因:一对一中,一个提供主键、另一个共享其主键,共享主键的对象可以set 提供主键的对象 然后添加到数据库中 方向弄反了 后果就是没人提供主键
    7、org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing:     异常环境:多对一添加 异常原因:在多的一端维护 ,没有添加级联
    8、javax.persistence.PersistenceException: [PersistenceUnit: JPA] Unable to configure EntityManagerFactory 异常原因:很多、实体管理器Factory没有成功创建,是注解的问题 9、org.hibernate.MappingException: Unable to find column with logical name: sid in org.hibernate.mapping. 异常环境:添加表做多对一关联映射 异常原因:表字段写反了,name添加表字段名referencedColumnName指向本表字段

     

    宝贝网址:

  • 相关阅读:
    55. 跳跃游戏
    45. 跳跃游戏 II
    对称的二叉树
    字符型图片验证码,使用tensorflow实现卷积神经网络,进行验证码识别CNN
    python版本升级及pip部署方法
    Two Sum [easy] (Python)
    工作中常用的linux命令(持续更新)
    PAT-1001. 害死人不偿命的(3n+1)猜想 (15)
    C++二维数组的动态声明
    19. Remove Nth Node From End of List(C++,Python)
  • 原文地址:https://www.cnblogs.com/W203654/p/2252298.html
Copyright © 2020-2023  润新知