on 04-01-2014 7:53 AM
Hi Experts,
I am trying to fetch data from mysql database into my SAPUI5 application. I follow blog but I get an error "The entity has no primary key attribute defined" in Java Resources under the model. Can anyone please help me in solving the error. I attached a screen shot of the error.
Thanks
Himadri
Hey mate,
You might be interested in the following: http://scn.sap.com/community/developer-center/cloud-platform/blog/2015/11/02/simple-application-to-m...
I gave access to HTML5 and Java code to get data from any database using JPA.
Cheers
Greg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Even I am trying to fetch data from mysql database into my SAPUI5 application. and follow the same blog OData producer using Apache Olingo with MySQL, JPA & Tomcat web server but
while running the service i am getting screen as shown in below. Can anyone please help me in solving the error.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi All
I am trying to fetch the data from MySQL and display it in one of the views in UI5 application project. I was able to display the contents of the table on the browser. For this, I had created a seperate Dynamic web project. I dint make use of oData for fetching the data. Now, I need to bind the servlet to the json model used in one of the views. Can you guys help me in achieving the same ?
Thanks in advance
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi all,
i also done all the settings but till i got the following errors
<error><code/><message xml:lang="en">java.lang.SecurityException: class "javax.persistence.PersistenceUtil"'s signer information does not match signer information of other classes in the same package</message></error>
jdk1.7.0_60
tomcat 7.0
Eclipse Juno Service Release 2
Build id: 20130225-0426
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have done all the required things you have mentioned in the blog and I have cross checked with all your comments mentioned above,still I am getting the error as shown below.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Experts,
I am getting an error "Servlet ODataServlet is not available". My code is
package model;
import java.io.Serializable;
import javax.persistence.*;
/**
* The persistent class for the customer_list database table.
*
*/
@Entity
@Table(name="customer_list")
public class CustomerList implements Serializable {
@Id @GeneratedValue long Id;
private static final long serialVersionUID = 1L;
@Column(nullable=false, length=50)
private String address;
@Column(nullable=false, length=50)
private String city;
@Column(nullable=false, length=50)
private String country;
@Column(nullable=false)
private int id;
@Column(length=91)
private String name;
@Column(nullable=false, length=6)
private String notes;
@Column(nullable=false, length=20)
private String phone;
@Column(nullable=false)
private byte sid;
@Column(name="`zip code`", length=10)
private String zip_code;
public CustomerList() {
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCity() {
return this.city;
}
public void setCity(String city) {
this.city = city;
}
public String getCountry() {
return this.country;
}
public void setCountry(String country) {
this.country = country;
}
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 String getNotes() {
return this.notes;
}
public void setNotes(String notes) {
this.notes = notes;
}
public String getPhone() {
return this.phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public byte getSid() {
return this.sid;
}
public void setSid(byte sid) {
this.sid = sid;
}
public String getZip_code() {
return this.zip_code;
}
public void setZip_code(String zip_code) {
this.zip_code = zip_code;
}
}
package main;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAContext;
import org.apache.olingo.odata2.processor.api.jpa.ODataJPAServiceFactory;
import org.apache.olingo.odata2.processor.api.jpa.exception.ODataJPARuntimeException;
public class EmployeeListServiceFactory extends ODataJPAServiceFactory {
private static final String PERSISTENCE_UNIT_NAME = "try";
@Override
public ODataJPAContext initializeODataJPAContext()
throws ODataJPARuntimeException {
ODataJPAContext oDatJPAContext = this.getODataJPAContext();
try {
EntityManagerFactory emf = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
oDatJPAContext.setEntityManagerFactory(emf);
oDatJPAContext.setPersistenceUnitName(PERSISTENCE_UNIT_NAME);
return oDatJPAContext;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
in web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>try</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>ODataServlet</servlet-name>
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
<param-value>main.EmployeeListServiceFactory</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ODataServlet</servlet-name>
<url-pattern>/emplist.svc/*</url-pattern>
</servlet-mapping>
</web-app>
Can anyone please help me to resolve the error....
Thanks
Himadri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Himadri,
I guess, Primary key column for "customer_list" table is
@Column(nullable=false)
private int id;
This should be
@Id
@Column(unique=true, nullable=false)
private int id;
remove the following line in beginning of class declaration.
@Id @GeneratedValue long Id;
and property "private static final long serialVersionUID = 1L;" is not part of column in database table.
Sathees Kumar P.
Thank you for your quick reply. I do the changes but the error is still coming. And if I remove "private static final long serialVersionUID = 1L;" it will give a warning "The serializable class CustomerList does not declare a static final serialVersionUID field of type long". Is my web.xml file coding ok or I have to change something in it???
Thanks
Himadri
Hi,
1. "private static final long serialVersionUID = 1L;" this line is required and annotation "
@Id @GeneratedValue long Id;" is not required for above line.
2. Where your getting this error while testing the OData Endpoint in browser or Eclipse editor itself?
or
Better you could re-start from beginning as mentioned in my blog.
It is mandatory that there should be minimum of one entity in Odata defined as primary key. When you are creating a Odata service you can define one primary key to solve this issue.
Midhun VP
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.