Waqas Ali
Waqas Ali

Reputation: 1652

GAE datastore + JPA + Odata in java

I am creating an application on GAE in which I have to provide a rest interface of database(datastore) using odata. I am using odata4j library for odata producer implementation. I am new to odata. I have provided a access layer on GAE datastore using jpa. Now what's my problem.

@Entity
@Table(name = "Submission")
//@IdClass(java.lang.Long.class)
public class Submission implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic
private Long submissionId;

private String status;
private Long userId;
private Date createdDate;

public Long getUserId() {
    return userId;
}

public void setUserId(Long userId) {
    this.userId = userId;
}

public Date getCreatedDate() {
    return createdDate;
}

public void setCreatedDate(Date createdDate) {
    this.createdDate = createdDate;
}

public Long getSubmissionId() {
    return submissionId;
}

public void setSubmissionId(Long submissionId) {
    this.submissionId = submissionId;
}

public String getStatus() {
    return status;
}

public void setStatus(String status) {
    this.status = status;
}

}

I have simple Entity Submission. Through EntityManager I persistent some Submission entities. When I hit the following odata url i get the all submissions

http://localhost:8888/odata.svc/Submission

I have some other entities and this work for all entities. I use $filter to query on entities and it works too. Now when I want to get a single entity using its id(primary key) I am getting the error that invalid key type. OData URL for getting single submission is

http://localhost:8888/odata.svc/Submission(12345567889)

After debuging the odata library what I found that in static method

typeSafeEntityKey(EntityManager em,EntityType<?> jpaEntityType,OEntityKey entityKey)

of JPAProducer class in odata library, there is a line from which we try to find out the type of id of submission entity

 Class<?> javaType = jpaEntityType.getIdType().getJavaType();

after getting the type we then try to find out what is its type. I am expecting that the id type should be java.lang.Long but It always give javax.jdo.identity.LongIdentity. In odata4j this type is not a valid due to which it throw exception.

Upon more debugging I found that the Submission entity has the @id-class value javax.jdo.identity.LongIdentity due to which getIdType() function give the id type LongIdentity.

In my submission entity class I try to use @Idclass annotation with value java.lang.Long but I get the error in console that

 **Class "com.convergent.model.Submission" has been specified with an object-id class   java.lang.Long which doesnt have a default constructor. All objectId classes MUST have a   default constructor.**

I don't know what to do because I am unable to use @Idclass and getIdType() give the LongIdentity type of id. thanks for reading

Upvotes: 2

Views: 490

Answers (1)

dened
dened

Reputation: 4310

Looks like this issue have been known since March 2012 and still not resolved: https://code.google.com/p/odata4j/issues/detail?id=149

Most probable odata4j doesn't support DataNucleus as a JPA ODataProducer. Nevertheless it is stated that it supports AppEngine's Datastore directly, here is example: http://code.google.com/p/odata4j/source/browse?repo=samples&name=0.4#hg%2Fodata4j-appengine

It should be possible to use odata4j with AppEngine's Datastore directly and simultaneously use JPA in other parts of your application, but one should be careful with caching.

UPDATE:

It looks like odata4j is dead, there have been no new releases since August 2012 and signs of development activity since April 2013... So I suggest you to find an alternative. You may try Apache Olingo, it should support GAE now: https://issues.apache.org/jira/browse/OLINGO-150

Upvotes: 2

Related Questions