Search code examples
javajpaglassfisheclipselink

EclipseLink ValidationException - non-entity [class long] as target entity in the relationship attribute [field providerId]


I received the following error when trying to deploy an an application to Glassfish. Apparently there's something incorrect with my relationships.

Error from Glassfish Server when attempting to deploy:

        ValidationException Exception Description: [class edu...clinic.Treatment] 
uses a non-entity [class long] as target entity in the relationship attribute 
[field providerId]

Many-to-One relationship in my 'Treatment' class file:

@Entiity
... 
@ManyToOne
    @JoinColumn(name = "provider_fk", referencedColumnName = "npi")
    private long providerId;

One-to-Many relationship in my 'Provider' class file:

 @Entity
    ...
@Id
    @Column(name = "NPI")
    private long npi;
...
    @OneToMany(mappedBy = "providerId", targetEntity=Treatment.class)
        @OrderBy
        private List<Treatment> treatments;

I believe my annotations are correct, but something is amiss. I'd appreciate any suggestions as to how to go about correcting this.


Solution

  • Try the following, in Treatment entity change

    private long providerId;
    

    to

    private Provider provider;
    

    in Provider entity change

    @OneToMany(mappedBy = "providerId", targetEntity=Treatment.class)
    

    to

    @OneToMany(mappedBy = "provider", targetEntity=Treatment.class)