cancel
Showing results for 
Search instead for 
Did you mean: 

Fetch data from mysql database into SAPUI5 application

former_member193103
Participant
0 Kudos

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

Accepted Solutions (0)

Answers (8)

Answers (8)

GregTutt
Explorer
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi All,

I have gone though this blog and its very helpful too. I need more help from you.

I am getting the following result but i want output in a structured manner (perfect table) fetching data from MySQL.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Satheeskumar Palaniappan,


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.

former_member193103
Participant
0 Kudos

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

Sathees_P
Participant
0 Kudos

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.

former_member193103
Participant
0 Kudos

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

Sathees_P
Participant
0 Kudos

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.

former_member193103
Participant
0 Kudos

Hi

I get the error in browser. I attached the screen shot of the error.

Sathees_P
Participant
0 Kudos

Hi,

By seeing the error, OData libraries are not detected from "/WebContent/WEB-INF/lib" by WebApplication.

Verify your steps with Topic 3 in the blog. All required libraries are copied to that folder?

former_member193103
Participant
0 Kudos

Hi Sathees,

I am using JPA version 2.0 and Platform EclipseLink 2.4x, and in your blog it is JPA version 2.1 and Platform EclipseLink 2.5x. Does the error come because of this???

Thanks

Himadri

midhun_vp
Active Contributor
0 Kudos

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

former_member193103
Participant
0 Kudos

Hi Midhun,

Thanks for your reply.how can I define the primary key? Can you please provide me some more information on this topic.

Thanks

Himadri

midhun_vp
Active Contributor
0 Kudos

You need to mark any field in the Odata service as primary key while creating a Odata service. Ex. In SAP while creating a Odata service we have option to mark it as primary key as given below, I am not sure about the MySQLDB.

Midhun VP

former_member193103
Participant
0 Kudos

I use "@Id @GeneratedValue long Id;" in my class and the error is removed.

Thanks

Himadri