You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Jan-Erik Öhman <Ja...@cybercom.com> on 2014/10/21 08:24:02 UTC
EdmSimpleTypeException - value object instead of navigation property?
Hi
I try to create a simple db model and expose it as Odata.
Doing the simplest case I could think of, a group-table and an employee table where each employee is member of a group.
I created a JPA-project, added the Olingo-jars etc and got part of it working.
The link to groups (/Test.svc/Groups) works well as exptected.
But when I try to list the Employees (/Test.svc/Employees?odata-debug=json) I get an exception:
org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException:
OData - JPA Runtime: Internal error [An exception occurred.]
org.apache.olingo.odata2.api.ep.EntityProviderException:
org.apache.olingo.odata2.core.ep.producer.XmlPropertyEntityProducer
org.apache.olingo.odata2.api.edm.EdmSimpleTypeException:
The type 'class model.Group' of the value object is not supported.
Olingo always assumes that the Group-property of my model is an Integer and not a navigation property?
No relation/navigation information is available in the metadata either.
I have tried to add JPA-annotations, Olingo-annotations but I simply can't get it to work.
I assume that I make some stupid beginners mistake, but I can't figure out what.
Once I can get this to work I can start using it in a real world scenario.
Any Ideas what I could be doing wrong?
My classes looks like:
public class MyFactory extends ODataJPAServiceFactory {
private static final Log log = LogFactory.getLog(MyFactory.class);
private static final String PUNIT_NAME = "aodata";
private static final int PAGE_SIZE = 5;
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = getODataJPAContext();
oDataJPAContext.setEntityManagerFactory(
JPAEntityManagerFactory.getEntityManagerFactory
(PUNIT_NAME));
oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
oDataJPAContext.setPageSize(PAGE_SIZE);
setDetailErrors(true);
return oDataJPAContext;
}
}
@Entity
@Table(name="groups")
@NamedQuery(name="Group.findAll", query="SELECT g FROM Group g")
public class Group implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(nullable=false, length=45)
private String name;
//bi-directional many-to-one association to Employee
@OneToMany(mappedBy="group")
private List<Employee> employees;
public Group() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public List<Employee> getEmployees() {
return this.employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
public Employee addEmployee(Employee employee) {
getEmployees().add(employee);
employee.setGroup(this);
return employee;
}
public Employee removeEmployee(Employee employee) {
getEmployees().remove(employee);
employee.setGroup(null);
return employee;
}
}
@Entity
@Table(name="employees")
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(length=45)
private String name;
//bi-directional many-to-one association to Group
@ManyToOne
@JoinColumn(name="groupId", nullable=false)
private Group group;
public Employee() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Group getGroup() {
return this.group;
}
public void setGroup(Group group) {
this.group = group;
}
}
I have zipped the complete Eclipse web project (including a Create and Insert SQL script) and put it at http://1drv.ms/1vCtZyh?
Best Regards,
Jan-Erik Öhman
RE: EdmSimpleTypeException - value object instead of navigation
property?
Posted by Jan-Erik Öhman <Ja...@cybercom.com>.
Thanks Christian.
I have tried the archetype (and just to be 100% sure, had a colleague download and run the jpa archetype on his machine). But that also fails on the relation parts. It does however produce navigation properties in the metadata.
When running the archetype and trying to navigate to Cars (either through navigation property or directly) we get the same EdmSimpleTypeException as we did in our own sample project.
URL: http://localhost:8080/my-car-service/MyFormula.svc/Manufacturers(1)/CarDetails?odata-debug=json
Exception (part of):
"stacktrace": {
"exceptions": [
{
"class": "org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException",
"message": "\"OData - JPA Runtime: Internal error [An exception occurred.]\"",
"invocation": {
"class": "org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException",
"method": "throwException",
"line": 96
}
},
{
"class": "org.apache.olingo.odata2.api.ep.EntityProviderException",
"message": "An exception occurred.",
"invocation": {
"class": "org.apache.olingo.odata2.core.ep.producer.XmlPropertyEntityProducer",
"method": "append",
"line": 74
}
},
{
"class": "org.apache.olingo.odata2.api.edm.EdmSimpleTypeException",
"message": "The type 'class com.sample.model.Manufacturer' of the value object is not supported.",
"invocation": {
"class": "org.apache.olingo.odata2.core.edm.EdmInt32",
"method": "internalValueToString",
"line": 98
}
}
Best Regards,
Jan-Erik Öhman
________________________________
From: Amend, Christian <ch...@sap.com>
Sent: Tuesday, October 21, 2014 16:08
To: user@olingo.apache.org
Subject: RE: EdmSimpleTypeException - value object instead of navigation property?
Hi,
I personally did not implement the JPA processor but I know there is an archetype as an example where you have a OneToMany relationship between Cars and Manufacturers. Maybe a look there can help.
The archetype can be found inside the GIT under the sample folder. Or via maven.
Best Regards,
Christian
From: Jan-Erik Öhman [mailto:Jan-Erik.ohman@cybercom.com]
Sent: Dienstag, 21. Oktober 2014 08:24
To: user@olingo.apache.org
Subject: EdmSimpleTypeException - value object instead of navigation property?
Hi
I try to create a simple db model and expose it as Odata.
Doing the simplest case I could think of, a group-table and an employee table where each employee is member of a group.
I created a JPA-project, added the Olingo-jars etc and got part of it working.
The link to groups (/Test.svc/Groups) works well as exptected.
But when I try to list the Employees (/Test.svc/Employees?odata-debug=json) I get an exception:
org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException:
OData - JPA Runtime: Internal error [An exception occurred.]
org.apache.olingo.odata2.api.ep.EntityProviderException:
org.apache.olingo.odata2.core.ep.producer.XmlPropertyEntityProducer
org.apache.olingo.odata2.api.edm.EdmSimpleTypeException:
The type 'class model.Group' of the value object is not supported.
Olingo always assumes that the Group-property of my model is an Integer and not a navigation property?
No relation/navigation information is available in the metadata either.
I have tried to add JPA-annotations, Olingo-annotations but I simply can't get it to work.
I assume that I make some stupid beginners mistake, but I can't figure out what.
Once I can get this to work I can start using it in a real world scenario.
Any Ideas what I could be doing wrong?
My classes looks like:
public class MyFactory extends ODataJPAServiceFactory {
private static final Log log = LogFactory.getLog(MyFactory.class);
private static final String PUNIT_NAME = "aodata";
private static final int PAGE_SIZE = 5;
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = getODataJPAContext();
oDataJPAContext.setEntityManagerFactory(
JPAEntityManagerFactory.getEntityManagerFactory
(PUNIT_NAME));
oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
oDataJPAContext.setPageSize(PAGE_SIZE);
setDetailErrors(true);
return oDataJPAContext;
}
}
@Entity
@Table(name="groups")
@NamedQuery(name="Group.findAll", query="SELECT g FROM Group g")
public class Group implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(nullable=false, length=45)
private String name;
//bi-directional many-to-one association to Employee
@OneToMany(mappedBy="group")
private List<Employee> employees;
public Group() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public List<Employee> getEmployees() {
return this.employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
public Employee addEmployee(Employee employee) {
getEmployees().add(employee);
employee.setGroup(this);
return employee;
}
public Employee removeEmployee(Employee employee) {
getEmployees().remove(employee);
employee.setGroup(null);
return employee;
}
}
@Entity
@Table(name="employees")
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(length=45)
private String name;
//bi-directional many-to-one association to Group
@ManyToOne
@JoinColumn(name="groupId", nullable=false)
private Group group;
public Employee() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Group getGroup() {
return this.group;
}
public void setGroup(Group group) {
this.group = group;
}
}
I have zipped the complete Eclipse web project (including a Create and Insert SQL script) and put it at http://1drv.ms/1vCtZyh
Best Regards,
Jan-Erik Öhman
RE: EdmSimpleTypeException - value object instead of navigation
property?
Posted by "Amend, Christian" <ch...@sap.com>.
Hi,
I personally did not implement the JPA processor but I know there is an archetype as an example where you have a OneToMany relationship between Cars and Manufacturers. Maybe a look there can help.
The archetype can be found inside the GIT under the sample folder. Or via maven.
Best Regards,
Christian
From: Jan-Erik Öhman [mailto:Jan-Erik.ohman@cybercom.com]
Sent: Dienstag, 21. Oktober 2014 08:24
To: user@olingo.apache.org
Subject: EdmSimpleTypeException - value object instead of navigation property?
Hi
I try to create a simple db model and expose it as Odata.
Doing the simplest case I could think of, a group-table and an employee table where each employee is member of a group.
I created a JPA-project, added the Olingo-jars etc and got part of it working.
The link to groups (/Test.svc/Groups) works well as exptected.
But when I try to list the Employees (/Test.svc/Employees?odata-debug=json) I get an exception:
org.apache.olingo.odata2.jpa.processor.api.exception.ODataJPARuntimeException:
OData - JPA Runtime: Internal error [An exception occurred.]
org.apache.olingo.odata2.api.ep.EntityProviderException:
org.apache.olingo.odata2.core.ep.producer.XmlPropertyEntityProducer
org.apache.olingo.odata2.api.edm.EdmSimpleTypeException:
The type 'class model.Group' of the value object is not supported.
Olingo always assumes that the Group-property of my model is an Integer and not a navigation property?
No relation/navigation information is available in the metadata either.
I have tried to add JPA-annotations, Olingo-annotations but I simply can't get it to work.
I assume that I make some stupid beginners mistake, but I can't figure out what.
Once I can get this to work I can start using it in a real world scenario.
Any Ideas what I could be doing wrong?
My classes looks like:
public class MyFactory extends ODataJPAServiceFactory {
private static final Log log = LogFactory.getLog(MyFactory.class);
private static final String PUNIT_NAME = "aodata";
private static final int PAGE_SIZE = 5;
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDataJPAContext = getODataJPAContext();
oDataJPAContext.setEntityManagerFactory(
JPAEntityManagerFactory.getEntityManagerFactory
(PUNIT_NAME));
oDataJPAContext.setPersistenceUnitName(PUNIT_NAME);
oDataJPAContext.setPageSize(PAGE_SIZE);
setDetailErrors(true);
return oDataJPAContext;
}
}
@Entity
@Table(name="groups")
@NamedQuery(name="Group.findAll", query="SELECT g FROM Group g")
public class Group implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(nullable=false, length=45)
private String name;
//bi-directional many-to-one association to Employee
@OneToMany(mappedBy="group")
private List<Employee> employees;
public Group() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public List<Employee> getEmployees() {
return this.employees;
}
public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
public Employee addEmployee(Employee employee) {
getEmployees().add(employee);
employee.setGroup(this);
return employee;
}
public Employee removeEmployee(Employee employee) {
getEmployees().remove(employee);
employee.setGroup(null);
return employee;
}
}
@Entity
@Table(name="employees")
@NamedQuery(name="Employee.findAll", query="SELECT e FROM Employee e")
public class Employee implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(unique=true, nullable=false)
private int id;
@Column(length=45)
private String name;
//bi-directional many-to-one association to Group
@ManyToOne
@JoinColumn(name="groupId", nullable=false)
private Group group;
public Employee() {
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public Group getGroup() {
return this.group;
}
public void setGroup(Group group) {
this.group = group;
}
}
I have zipped the complete Eclipse web project (including a Create and Insert SQL script) and put it at http://1drv.ms/1vCtZyh
Best Regards,
Jan-Erik Öhman