pat3ck029
pat3ck029

Reputation: 273

Hibernate @ManyToOne "Target Entity is not defined"

I have two entities, and when i use @ManyToOne annotation, i'm getting an error saying "Target Entity is not defined".

I'm just following a tutorial and i can't seem to find what i did wrong.

        @Entity
        @Table(name="BEO_TABLE")
        public class BeoBean {

            @Id
            @GeneratedValue
            @Column(name="Beo_Id")
            private int beoId;

    //other variables


            @OneToMany(mappedBy="beo")
            private List<EventsBean> listOfEvents = new ArrayList<EventsBean>();

    //getters and setters
}

AND

@Entity
@Table(name="EVENTS_TABLE")
public class EventsBean {

    //other variables

    @ManyToOne //error here
    @JoinColumn(name="Beo_Id")
    private BeoBean beo;

//getters and setters
}

Thanks for your help

Upvotes: 5

Views: 11376

Answers (3)

JJMB
JJMB

Reputation: 11

225/5000 I often had this kind of false error in Eclipse, and it is solved by cleaning the project.

Select the project, then click the Project / Clean ... menu and then Clean button

Worked for me once again.

JJMB

Upvotes: 1

KameshG
KameshG

Reputation: 53

Fix your persistence unit in eclipse. Add BeoBean to the PU. You should be sorted

Upvotes: 1

GHajba
GHajba

Reputation: 3691

This error has nothing to do with your application. It works fine but the error is in Eclipse.

To remove this (and other JPA) error message simply disable the JPA validation under Window -> Preferences -> Validation and here remove the checks from JPA Validator.

Generally most applications can be developed without any validators because bigger projects' validation slows down compiling in eclipse way too much. In this case click Disable all in the same window below the table of validators.

Upvotes: 11

Related Questions