Search code examples
javahibernateintellij-idea

'Many To One' attribute type should not be 'Persistence Entity'


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.


Solution

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