Categories
Development

@ManyToOne references an unknown entity

I am trying to do one to many relations (table EmployeeEntity and AddressEntity,but when i buid i get errors.

@Data
@EqualsAndHashCode(exclude = "eeEntity")

public class AddressEntity {
..

@OneToMany(mappedBy = "addressEntity", targetEntity = com.howtodoinjava.demo.model.AddressEntity.class,cascade = CascadeType.ALL)
    private Set<EmployeeEntity> eeEntity;

    public AddressEntity(String city, EmployeeEntity... eeEntity) {
        this.city = city;
        this.eeEntity = Stream.of(eeEntity).collect(Collectors.toSet());
        this.eeEntity.forEach(x -> x.setAddressEntity(this));
    }
---------
@Data
@Entity
public class EmployeeEntity {
...
@OneToMany(mappedBy = "addressEntity", targetEntity = com.howtodoinjava.demo.model.AddressEntity.class,cascade = CascadeType.ALL)
    private Set<EmployeeEntity> eeEntity;

    public AddressEntity(String city, EmployeeEntity... eeEntity) {
        this.city = city;
        this.eeEntity = Stream.of(eeEntity).collect(Collectors.toSet());
        this.eeEntity.forEach(x -> x.setAddressEntity(this));
    }

Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘entityManagerFactory’ defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.howtodoinjava.demo.model.EmployeeEntity.addressEntity references an unknown entity: com.howtodoinjava.demo.model.AddressEntity

Caused by: org.hibernate.AnnotationException: @OneToOne or @ManyToOne on com.howtodoinjava.demo.model.EmployeeEntity.addressEntity references an unknown entity: com.howtodoinjava.demo.model.AddressEntity

Can some one help me understand why i get this.

Leave a Reply

Your email address will not be published. Required fields are marked *