Olingo – Requested entity could not be found

Let the world know ...Tweet about this on TwitterShare on Google+0Share on Facebook0Email this to someoneShare on LinkedIn0

Lately I was playing around with HCP and Olingo and wanted to expose a JPA model as OData. I created some data using EJB and then tried to read this data via OData. Accessing the collection gave me a list of created entities:

To access one entity, it is just using its ID as key and call it in the browser: http://localhost:8080/service.svc/Events(8L) What I got as a response was an error message: Requested entity could not be found.

<error xmlns=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata”>

<code/>

<message xml:lang=”en-US”>Requested entity could not be found.</message>

</error>

Thing is: the entity was there. I know it (I have DB access), I just could not access it. Turned out that the version of org.eclipse.persistence.jpa I was using does not like when the @ID key is of type long (8L). Using version >= 2.5.2 solved the issue for me. Changing my pom.xml:

<dependency>

    <groupId>org.eclipse.persistence</groupId>

    <artifactId>org.eclipse.persistence.jpa</artifactId>

    <version>2.5.2</version>

</dependency>

Now I can access the entity using the ID as key in the URL:

Note

You`ll have to declare org.eclipse.persistence.jpa in your pom.xml when you are using a non-JTA data source (RESOURCE_LOCAL) and when you create your entity manager like this:

ds = (javax.sql.DataSource) ctx.lookup(“java:comp/env/jdbc/DefaultDB”);

Map properties = new HashMap();

properties.put(PersistenceUnitProperties.NON_JTA_DATASOURCE, ds);

emf = Persistence.createEntityManagerFactory(“JPATest”, properties);

If you just use

emf = Persistence.createEntityManagerFactory(“JPATest”);

You won`t have to declare it in pom.xml. Either way, if you do not declare it, or use the wrong version, you`ll end up getting the same error: Requested entity could not be found. The version of the library delivered with HCP is 2.75.8.4 org.eclipse.persistence.jpa_2.4.1.v20121003-ad44345 and looking the Google results, this version is also not working 100% when the @ID is long. Best solution should be to declare the dependency in pom.xml and use as version at least 2.5.2.

Let the world know ...Tweet about this on TwitterShare on Google+0Share on Facebook0Email this to someoneShare on LinkedIn0

Leave a Reply

Your email address will not be published. Required fields are marked *