zoukankan      html  css  js  c++  java
  • JPA实体关系映射:@ManyToMany多对多关系、@OneToMany@ManyToOne一对多多对一关系和@OneToOne的深度实例解析

    JPA实体关系映射:@ManyToMany多对多关系、@OneToMany@ManyToOne一对多多对一关系和@OneToOne的深度实例解析

    今天程序中遇到的
    错误一
    org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: com.hibernate.SubStation.bays

    错误解决方法
    org.hibernate.AnnotationException: Collection has neither generic type or OneToMany.targetEntity() defined: org.svse.org.model.Order.orderItems

    在用annotation做数据库映射一对多和多对一的时候要注意:因为这个问题只有在用annotation的时候才有,用xml文件的时候就没有在一对多关系映射中

    一的一方直接写Set就可以不用指定相应的元素类型!!
    请 检查orderItems这个属性是否使用了泛型,   如:Set<OrderItem>.
    如 果未使用泛型,请在OneToMany注释中使用targetEntity指定元素的类型

    如果你用的是:List<OrderItem> 请改为Set<OrderItem>

    错误二
    org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: com.hibernate.Bay.group in com.hibernate.SubStation.bays
    错误解决方法
    在用annotation做数据库映射一对多和多对一的时候要注意:
    @OneToMany(mappedBy = "news_type", cascade = CascadeType.ALL,fetch = FetchType.LAZY)  这里的mappedBy 要对应
    @ManyToOne
    @JoinColumn(name="news_type", nullable=true, insertable = true, updatable = true)
    private NewsType newsType;的NewsType对象名,也就是newsType而不是字段名news_type。

    错误三
    node to traverse cannot be null!
    出现这种问题是因为HQL语句出现问题,引起内部查询对象为空,无法处理为空值引起的。解决方法,检查HQL语句(尤其是关键字)。

  • 相关阅读:
    MySQL的FORMAT函数用法规则
    jetbrains idea/webstorm等(注册,激活,破解码,一起支持正版,最新可用)(2017.3.16更新)【转】
    用户价值模型 CITE :https://www.jianshu.com/p/34199b13ffbc
    用户生命周期模型
    机器学习十大常用算法(CITE 不会停的蜗牛 ) interesting
    Linux 安装Oracle11g完整安装图文教程另附基本操作 (分享)
    oracle 命中率
    SQL学习总结笔记
    hash join
    Tomcat详细安装配置
  • 原文地址:https://www.cnblogs.com/achengmu/p/9476495.html
Copyright © 2011-2022 走看看