Search code examples
javajpajava-8weblogiceclipselink

What determines where eclipselink is looking for @Column, @Temporal and @Id annotations?


I try to migrate my project from Java 6 + WebLogic 12.1.1 + EclipseLink 2.5.0 to Java 8 + WebLogic 12.1.3 + EclipseLink 2.6.4.

In all my EclipseLink entities I have @Id, @Temporal and @Column annotations for getters and not for fields. But when I deploy my app to the newer WebLogic it fails with errors like this

org.eclipse.persistence.exceptions.ValidationException Exception Description: Entity class [class com.example.MyEntity] has no primary key specified. It should define either an @Id, @EmbeddedId or an @IdClass

How can I tell EclipseLink to look for this annotation above getId() method, and not above private id field?

Maybe I should ask admins to tune WebLogic in some way?

EDIT

an example of entity

@Entity
@ReadOnly
@Table(name="CONTRACT_OPTION", schema="SCH")

public class ContractOption implements Serializable {
    private static final long serialVersionUID = 1L;
    private Long contractOptionId;
    private String contractOptionName;
    private BigDecimal sortOrder;
    private Date date;
    public ContractOption() {}


    @Id
    @Column(name="CONTRACT_OPTION_ID")
    public Long getContractOptionId() {
        return this.contractOptionId;
    }

    public void setContractOptionId(Long contractOptionId) {
        this.contractOptionId = contractOptionId;
    }


    @Column(name="CONTRACT_OPTION_NAME")
    public String getContractOptionName() {
        return this.contractOptionName;
    }

    public void setContractOptionName(String contractOptionName) {
        this.contractOptionName = contractOptionName;
    }


    @Column(name="SORT_ORDER")
    public BigDecimal getSortOrder() {
        return this.sortOrder;
    }

    public void setSortOrder(BigDecimal sortOrder) {
        this.sortOrder = sortOrder;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="DATE")
    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    @Override
    public String toString() {
        return getContractOptionName();
    }
}

Solution

  • I found the solution. Class annotation @Access determines where eclipselink will look for @Id and @Temporal annotations. You can set it as @Access(AccessType.PROPERTY), or @Access(AccessType.FIELD)