I have @MappedSuperclass AbstractEntity which I use for all my @Entity classes. It works fine while the superclass is in the same Eclipse project as my entities. But since I use this superclass among several projects, I just want to split it into my JAR file. When I do this (and of course I add a JAR file to the build path), Eclipse gives an error for each of my @Entity classes:
An object does not have a specific primary key attribute.
Eclipse highlights the @Entity annotation as the source of the error. Of course, all classes inherit from this AbstractEntity. The package name is the same in both projects. The JAR project has all the necessary assembly paths - there are no errors in the project JAR file containing AbstractEntity.
When I deploy this to my application server (JBoss 7.1), it works fine. This makes me think that this is simply an Eclipse issue where it falsely identifies the error.
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; } }
An example of a simple Entity class:
@Entity public class TestEntity extends AbstractEntity { ... }
I saw some other posts saying that the problem may be that the annotations in the superclass are on getters instead of fields - this is only a problem if you don't have other JPA annotations inside your objects, which I am doing. Any ideas?
Ryanc source share