留言板

when i do update operation

vikash kumar,修改在7 年前。

when i do update operation

New Member 帖子: 4 加入日期: 16-8-3 最近的帖子
when i do update operation i got this exception plese help me...
16:52:12,035 WARN [http-bio-8090-exec-5][EmployeePersistenceImpl:706] No Employee exists with the primary key 0
thumbnail
David H Nebinger,修改在7 年前。

RE: when i do update operation

Liferay Legend 帖子: 14918 加入日期: 06-9-2 最近的帖子
You'll have to trace through your code. Looks like you're not using a real pk value.






Come meet me at the LSNA!
vikash kumar,修改在7 年前。

RE: when i do update operation

New Member 帖子: 4 加入日期: 16-8-3 最近的帖子
how to use real pk
thumbnail
Olaf Kock,修改在7 年前。

RE: when i do update operation

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
vikash kumar:
how to use real pk


Please show us the code you use when you get the mentioned error message. If you update a custom entity, that entity should have a proper id, so that it's clear which object should be updated.
vikash kumar,修改在7 年前。

RE: when i do update operation

New Member 帖子: 4 加入日期: 16-8-3 最近的帖子
controller class-
package com.azstrel;

import java.io.IOException;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.db.model.Employee;
import com.db.model.impl.EmployeeImpl;
import com.db.service.EmployeeLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class EmployeeContrl extends MVCPortlet {

/*
* /public void ADD(ActionRequest actionRequest, ActionResponse
* actionResponse) throws IOException, PortletException, PortalException,
* SystemException { System.out.println("#################"); }
*/

public void addEmployee(ActionRequest actionRequest,
ActionResponse actionesponse) throws IOException, PortletException,
com.liferay.portal.kernel.exception.SystemException {
System.out.println("###############################################");
long empID;
Employee employee = new EmployeeImpl();

try {
empID = CounterLocalServiceUtil.increment(Employee.class.getName());
empID = ParamUtil.getLong(actionRequest, "empID");
String fname = ParamUtil.getString(actionRequest, "firstName");
String lname = ParamUtil.getString(actionRequest, "lastName");
System.out.println("insert");
employee = EmployeeLocalServiceUtil.createEmployee(empID);
employee.setEmpID(empID);
employee.setFirstName(fname);
employee.setLastName(lname);

EmployeeLocalServiceUtil.addEmployee(employee);
System.out.println("record submitted");
} catch (SystemException e) {

}
}

public void deleteEmployee(ActionRequest actionRequest,
ActionResponse actionResponse) {
try {
/*
* String param = ParamUtil.get(actionRequest, "param2",
* StringPool.BLANK);
*/
// System.out.println("!!!!!!!!!!!!!!!!!!", +param);
long empID = ParamUtil.getLong(actionRequest, "empID");
Employee employee = EmployeeLocalServiceUtil.deleteEmployee(empID);
actionRequest.setAttribute("employeeObject", employee);

System.out.println("delete*****************############" + empID);
// navigate to add student jsp page
actionResponse.setRenderParameter("mvcPath",
"/html/jsps/delete.jsp");
} catch (Exception e) {
System.out.println("delete not successful");
e.printStackTrace();
}
}

public void upEmployee(ActionRequest actionRequest,

ActionResponse actionResponse) throws IOException, PortletException,
PortalException {
System.out.println("###############################################");
long empID;
Employee employee = new EmployeeImpl();
try {
empID = CounterLocalServiceUtil.increment(Employee.class.getName());
System.out
.println("###############################################");

empID = ParamUtil.getLong(actionRequest, "empID");
String fname = ParamUtil.getString(actionRequest, "firstName");
String lname = ParamUtil.getString(actionRequest, "lastName");
System.out.println("update");
employee = EmployeeLocalServiceUtil.getEmployee(empID);

if (employee != null) {
employee.setEmpID(empID);
employee.setFirstName(fname);
employee.setLastName(lname);

employee = EmployeeLocalServiceUtil.updateEmployee(employee);
actionRequest.setAttribute("employeeObject", employee);

System.out.println("update****" + employee);

System.out.println("record updated");
} else {
System.out.println("record not submitted");
}

actionResponse.setRenderParameter("mvcPath",
"/html/jsps/update_Employee.jsp");

} catch (SystemException e) {
System.out.println("exception catch");
e.printStackTrace();

}
}

public void getEmployee(ActionRequest actionRequest,
ActionResponse actionResponse) throws IOException, PortletException {
try {
long empID = ParamUtil.getLong(actionRequest, "empID");
System.out.println(empID);
String cmd = ParamUtil.getString(actionRequest, "cmd");
Employee employee = EmployeeLocalServiceUtil.getEmployee(empID);
System.out.println("Employee ****************" + employee);
if (employee != null) {
System.out.println("Employee Object#######:---");
actionRequest.setAttribute("employeeObject", employee);
System.out.println("REcords Are:---");
actionResponse.setRenderParameter("mvcPath",
"/html/jsps/display_employee.jsp");
} else if (cmd.equals("VIEW")) {
// navigate to add Employee jsp page
actionResponse.setRenderParameter("mvcPath", "view.jsp");
}

} catch (Exception e) {
e.printStackTrace();

}
}
}

service builder-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.2.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_2_0.dtd">
<service-builder package-path="com.db">
<author>tech.azstrel</author>
<namespace>azstrel</namespace>

<entity name="Employee" local-service="true" remote-service="true" table="employee">

<!-- PK fields -->

<column name="empID" type="long" primary="true" />

<!-- Group instance -->

<column name="firstName" type="String" />

<column name="lastName" type="String" />
<!-- Finder methods -->
<finder name="byEmpID" return-type="Collection">
<finder-column name="empID"/>
</finder>

</entity>
</service-builder>

update.jsp--
<%@page import="java.io.Writer"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.db.service.EmployeeLocalServiceUtil"%>
<%@page import="java.util.List"%>
<%@page import="com.db.model.Employee"%>

<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet"%>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
<portlet:actionURL var="updateEmployeeActionURL" windowState="normal" name="upEmployee">
<portlet:param name="cmd" value="UPDATE"/>
</portlet:actionURL>
<h2>Update Employee</h2>

<%
List<Employee> employeeList=EmployeeLocalServiceUtil.getEmployees(0,EmployeeLocalServiceUtil.getEmployeesCount());

Employee selecteEmployeetObject=(Employee)renderRequest.getAttribute("employeeObject");
%>
<form action="<%=updateEmployeeActionURL.toString()%>" name="employeeForm" method="POST">
<b>Select Employee ID</b><br>
<select name="<portlet:namespace/>empId"onchange="submitform(this.value);">
<option>--select--</option>
<%for(Employee employee:employeeList){%>
<option
value="<%=employee.getEmpID()%>"<%=selecteEmployeetObject!=null&&selecteEmployeetObject.getEmpID()==employee.getEmpID()?"selected":""%>>
<%=employee.getEmpID()%></option>
<%} %>
</select><br>
<%if(selecteEmployeetObject!=null){%>
<b>First Name</b><br/>
<input type="text" name="<portlet:namespace/>firstName"id="<portlet:namespace/>firstName" value="<%=selecteEmployeetObject.getFirstName()%>"/><br/>
<b>Last Name</b><br/>
<input type="text" name="<portlet:namespace/>lastName" id="<portlet:namespace/>lastName" value="<%=selecteEmployeetObject.getLastName()%>"/><br/>
<br/>
<input type="button" name="updateEmployee" id="updateEmployee" value="Update Employee" onclick="updateEmployeeRecord();"/>
<%}%>
</form>
<script>
function submitform(selectedValue){

// if(selectedValue!="-1"){
document.employeeForm.submit();


}
function updateEmployeeRecord()
{
document.employeeForm.action="<%=updateEmployeeActionURL.toString()%>"
document.employeeForm.submit();
}
</script>
thumbnail
Olaf Kock,修改在7 年前。

RE: when i do update operation

Liferay Legend 帖子: 6403 加入日期: 08-9-23 最近的帖子
Thanks for the code - you could make it easier to read (and motivate others to answer) if you used the formatting options.
That being said, your error message states a problem in EmployeePersistenceImpl:706, which you don't post. From the code that you posted, it seems odd that the "addEmployee" uses an id that's provided by the UI: A new id should be provided by the underlying persistence layer. And if your addEmployee.
Let us know what kind of code you have in EmployeePersistenceImpl, line 706, especially what message that's in. You might just want to set a breakpoint there and inspect the values and the callstack yourself.