2

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();
    }
}
Xentai
  • 69
  • 11
  • is this https://bugs.eclipse.org/bugs/show_bug.cgi?id=429992 what you are hitting may be? Also show the actual mappings and make sure you are using the proper imports. – Eugene Jan 10 '17 at 09:38
  • @Eugene, I dont have any lambdas in my entities. – Xentai Jan 10 '17 at 09:41
  • can you see if any of these help? http://stackoverflow.com/questions/21397393/jpa-entity-has-no-primary-key – Eugene Jan 10 '17 at 09:43
  • @Eugene no, it has nothing to do with my problem... – Xentai Jan 10 '17 at 09:48
  • so post your ACTUAL class – Neil Stockton Jan 10 '17 at 10:36
  • @Neil Stockton done – Xentai Jan 10 '17 at 10:49
  • Looks perfectly fine to me, and I have such things in my apps that all work fine with a different JPA provider. Raise a bug on your JPA provider (since it is throwing the exceptions not WebLogic). Assume the class is defined in persistence.xml (or can be found on the classpath if "unlisted") – Neil Stockton Jan 10 '17 at 10:55
  • 1
    You can always specify the @Access(AccessType.PROPERTY) on the entity, but shouldn't need to if there are no other field level persistence properties. Turn on logging and see why it would be defaulting the access type to something different. Check the classes are recompiled with the new JDK as the java versions might be causing issues somehow. – Chris Jan 10 '17 at 19:31

1 Answers1

2

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)

Xentai
  • 69
  • 11