Hibernate: Used mappedBy on class that extends another class annotated as JoinedSubclass?

后端 未结 3 1562
迷失自我
迷失自我 2021-02-19 09:46

The following doesn\'t work:

@Entity
class Owner {

  @OneToMany(mappedBy=\"owner\", cascade = {CascadeType.ALL})
  protected Set getBSet() {
    ..
  }         


        
相关标签:
3条回答
  • 2021-02-19 10:12

    I'd double check your real implementation. I used your sample code and after adding an @Id everything worked as expected. Even IntelliJ says getBSet() is associated with B.owner.

    0 讨论(0)
  • 2021-02-19 10:13

    Try adding targetEntity = Transaction.class. This worked for me when I was using SINGLE_TABLE inheritance. I didn't try it with JOIN.

    @Entity
    class Owner {
    
      @OneToMany(mappedBy="owner", cascade = {CascadeType.ALL}, targetEntity = Transaction.class)
      @Where(clause = "tableType='I'")
      protected Set<B> getBSet() {
        ..
      }
    
    }
    
    0 讨论(0)
  • 2021-02-19 10:16

    It's a Hibernate oddity, but it's deliberate. I have a blog post up with background information, links and a workaround for the JOINED solution.

    0 讨论(0)
提交回复
热议问题