Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

ids for this class must be manually assigned before calling save()

843830Mar 27 2007 — edited Mar 28 2007
I get this error when calling the entity managers persist method, i'm not exactly sure what it means but i gather its saying that i need to set the id before i save it.....duh, but i've set the id already, here is the entity class i'm using:

@Entity
@Table(name = "committee")
public class Committee implements Serializable {


private String committeeID;
private String committeeName;
private String committeeType;

/** Creates a new instance of Committee */
public Committee() {
}

public Committee(String committeeID) {
this.committeeID = committeeID;
}


public Committee(String committeeID, String committeeName, String committeeType) {
this.committeeID = committeeID;
this.committeeName = committeeName;
this.committeeType = committeeType;
}

@Id
@Column(name = "committeeID", nullable = false)
public String getCommitteeID() {
return this.committeeID;
}

public void setCommitteeID(String committeeID) {
this.committeeID = committeeID;
}

@Column(name = "committeeName", nullable = false)
public String getCommitteeName() {
return this.committeeName;
}



public void setCommitteeName(String committeeName) {
this.committeeName = committeeName;
}


@Column(name = "committeeType", nullable = false)
public String getCommitteeType() {
return this.committeeType;
}


public void setCommitteeType(String committeeType) {
this.committeeType = committeeType;
}


@Override
public int hashCode() {
int hash = 0;
hash += (this.committeeID != null ? this.committeeID.hashCode() : 0);
return hash;
}

@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Committee)) {
return false;
}
Committee other = (Committee)object;
if (this.committeeID != other.committeeID && (this.committeeID == null || !this.committeeID.equals(other.committeeID))) return false;
return true;
}

@Override
public String toString() {
return "committeeTest.Committee[committeeID=" + committeeID + "]";
}

}


here is the client i use which is a servlet:

public class BeanTester extends HttpServlet {

/** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
* @param request servlet request
* @param response servlet response
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String committeeID = request.getParameter("committeeID");
String committeeName = request.getParameter("committeeName");
String committeeType = request.getParameter("committeeType");

out.println("<html>");
out.println("<head>");
out.println("<title>Servlet BeanTester</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet BeanTester at " + request.getContextPath () + "</h1>");
try {
Context jndiContext = getInitialContext();
Object ref = jndiContext.lookup("ComSessionBean/remote");
ComSessionRemote dao = (ComSessionRemote) PortableRemoteObject.narrow(ref,ComSessionRemote.class);

Committee com = new Committee(committeeID);
//com.setCommitteeID(committeeID);
com.setCommitteeName(committeeName);
com.setCommitteeType(committeeType);


dao.createCommittee(com);

//print out a new committee object

Committee comtest1 = dao.findCommittee(committeeID);
out.println(comtest1.getCommitteeID());
out.println(comtest1.getCommitteeName());
out.println(comtest1.getCommitteeType());
} catch(javax.naming.NamingException ne)
{
out.println(ne.getMessage());
}
out.println("</body>");
out.println("</html>");

out.close();
}

Any help on how to fix this would be much appreciated
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2007
Added on Mar 27 2007
5 comments
6,994 views