@Entity not recognizing the @Id in a @MappedSuperclass
I am fairly certain those are valid mappings.
The JPA 2.0 spec provides this example when talking about MappedSuperClasses (section 2.11.2):
@MappedSuperclass
public class Employee {
@Id protected Integer empId;
@Version protected Integer version;
@ManyToOne @JoinColumn(name="ADDR") protected Address address;
public Integer getEmpId() { ... }
public void setEmpId(Integer id) { ... }
public Address getAddress() { ... }
public void setAddress(Address addr) { ... }
}
// Default table is FTEMPLOYEE table
@Entity public class FTEmployee extends Employee {
// Inherited empId field mapped to FTEMPLOYEE.EMPID
// Inherited version field mapped to FTEMPLOYEE.VERSION
// Inherited address field mapped to FTEMPLOYEE.ADDR fk
// Defaults to FTEMPLOYEE.SALARY protected Integer salary;
public FTEmployee() {}
public Integer getSalary() { ... }
public void setSalary(Integer salary) { ... }
}
When using mixed access you have to specify the access type. See Eclipse Dali bug 323527 for giving a better validation error when both fields and properties are annotated.
Option 1 : Annotate the getVersion() method instead, only properties are annotated.
Option 2 : Specify mixed access type as follows:
@MappedSuperclass
@Access(AccessType.PROPERTY)
public abstract class FinanceEntityBean {
protected Long id;
@Version
@Access(AccessType.FIELD)
private long version;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public Long getId() {
return id;
}
public void setId(final Long id) {
this.id = id;
}
}
If FinanceEntityBean
is defined in a different Eclipse project from Tag
, you may be suffering from the Dali bug "No primary key attribute in other plug-in project".
The workaround is to list FinanceEntityBean
in the persistence.xml
file associated with Tag
.