I've got a @MappedSuperclass AbstractEntity that I use for all of my @Entity classes. It works perfectly as long as the superclass is in the same Eclipse project as my entities. But since I reuse this superclass among several projects, I just want to break it out into its own JAR file. When I do that (and of course I add the JAR file to the build path), Eclipse gives an error on every one of my @Entity classes:
The entity has no primary key attribute defined.
Eclipse highlights the @Entity annotation as the source of the error. Of course all of the classes do inherit from this AbstractEntity. The package name is the same in both projects. The JAR project has all necessary build paths - there are no errors in the JAR file project containing the AbstractEntity.
When I deploy this to my app server (JBoss 7.1), it works fine. This makes me think it is just an Eclipse issue where it is falsely identifying an error.
The Abstract Entity:
package com.xyc.abc;
import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
private static final long serialVersionUID = 1L;
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
Simple Entity Class Example:
@Entity
public class TestEntity extends AbstractEntity {
...
}
I've seen some other posts saying that the problem might be that the annotations in the superclass are on getters instead of on the fields - this is only a problem if you don't have other JPA annotations inside your entities, which I do. Any ideas?