41

I'm trying out IntelliJ IDEA and it's warning me of a Hibernate association that I don't quite understand.

One Side:

@Entity
@Table(name = "MY_REQ_ASSIGNEE")
public class MyRequestAssignee extends BaseUser {
    //...
    @OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.ALL}, mappedBy = "myRequestAssignee")
    private Collection<MyRequest> myRequests = new ArrayList<>();
    //...
}

Many Side:

@Entity
@Table(name = "MY_REQUEST")
public class MyRequest implements Persistable {

   //...
   @ManyToOne(fetch=FetchType.EAGER)
   @JoinColumn(name="ASSIGNEE_ID")
   private MyRequestAssignee myRequestAssignee;
   //...
}

(Persistable is just an interface that has the id property to make sure Hibernate has access to it.)

I see the MyRequestAssignee type underlined in red and the message reads 'Many To One' attribute type should not be 'Persistence Entity'. Are there something wrong with my relationships?

For a sanity check, I looked at this post and this post too.

Community
  • 1
  • 1
riddle_me_this
  • 8,575
  • 10
  • 55
  • 80

3 Answers3

110

I found this to be caused by the child entity not being defined in hibernate.cfg.xml. The error message could be improved.

Phil Carter
  • 1,265
  • 1
  • 10
  • 9
1

I'm getting this issue in my multi-module Gradle project with Quarkus in IntelliJ, where I have a OneToOne reference from an entity of module A to an entity of module B.

enter image description here

The code works, so I guess it could be a false flag of IntelliJ

Marian Klühspies
  • 15,824
  • 16
  • 93
  • 136
0

This question is a bit old, but I just wanted to add that this can also be caused by a conflicting hibernate .hbm mapping file and JPA annotations. I ran into this error message when converting old mapping files to annotations and forgot to comment out one of the old mapping files.

Travieso
  • 427
  • 3
  • 13