i want to create a simple project management application at the SAP NetWeaver Cloud (Java) Users can add persons to projects and define the working hours of a person who works on a project.
I created successfully a small application logic. However it's not clear to me how i should define the persistent data objects. And how to store and read the data on the right way.
I created the classes "Project" and "Person" to add data. (see at end person.java & project.java)
How can I create a relation between them and store the working hours of a person. (depending on the project)
On an ERM i know the solution. A 1:n relation between Person and Project and an extra table between them with "projectID","personID" and "workingHours".
So far the app writes data with the function "addNewPerson":
addNewPerson : function( sFirstName, sLastName, oTable ) {
var _this = this;
_this.odataServiceUrl = personsListOdataServiceUrl;
jQuery.ajax({
url : _this.odataServiceUrl + "/Person?$format=json",
type : 'POST',
contentType : 'application/json',
data : JSON.stringify({
firstName : sFirstName,
lastName : sLastName
}),
success : function(data) {
_this.getView().getModel().refresh();
oTable.unbindRows().bindRows("/Person");
},
error : function(jqXHR, textStatus, errorThrown) {
sap.ui.commons.MessageBox.alert("Failed to add person: " + textStatus+ "\n" + errorThrown);
}
}); },
To read the data i simple bind the rows to the object.
So, how can i create the data objects the right way? And how can i read and write the data to the objects?
Thank you very much,
Martino
Person.java:
package com.sap.netweaver.cloud.sample;
import javax.persistence.*;
@Entity
@Table(name = "T_PERSON")
@NamedQuery(name = "AllPersons", query = "select p from Person p")
public class Person {
@Id
@GeneratedValue
private long id;
@Basic
private String firstName;
@Basic
private String lastName;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public void setFirstName(String param) {
this.firstName = param;
}
public String getFirstName() {
return firstName;
}
public void setLastName(String param) {
this.lastName = param;
}
public String getLastName() {
return lastName;
}
}
Project.java:
package com.sap.netweaver.cloud.sample;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@Entity
@Table(name = "T_PROJECT")
@NamedQuery(name = "AllProjects", query = "select p from Project p")
public class Project {
@Id
@GeneratedValue
private long id;
@Basic
private String projectName;
@Basic
private String projectDesc;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public void setProjectName(String param) {
this.projectName = param;
}
public String getProjectName() {
return projectName;
}
public void setProjectDesc(String param) {
this.projectDesc = param;
}
public String getProjectDesc() {
return projectDesc;
}
}