• Post Reply Bookmark Topic Watch Topic
  • New Topic

Entity Bean - Null primary key returned by ejbCreate  RSS feed

 
Suneesh Raman
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am getting the following exception . I am using MySQL as my back end and using the autonumber created as primary key

[#|2005-02-02T14:25:46.462+0530|INFO|sun-appserver-pe8.0.0_01|javax.enterprise. system.container.ejb|_ThreadID=13;|
javax.ejb.EJBException: Null primary key returned by ejbCreate method
at com.sun.ejb.containers.EntityContainer.postCreate(EntityContainer.java:703)
at com.sun.ejb.containers.EJBHomeInvocationHandler.invoke(EJBHomeInvocationHandler .java:169)
at $Proxy6.create(Unknown Source)
at com.forum.ejb._ForumHome_Stub.create(Unknown Source)
at org.apache.jsp.test.testForum_jsp._jspService(testForum_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:263)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:210)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:246)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:499)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil terChain.java:236)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterCha in.java:55)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.ja va:145)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:141)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 220)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextVal ve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 168)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:144)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:133)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:539)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java :134)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:254)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:11 4)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingVal ve.java:166)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:936)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:165)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:683)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnecti on(Http11Protocol.java:604)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:542)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:6 47)
at java.lang.Thread.run(Thread.java:536)
|#]

[#|2005-02-02T14:25:46.472+0530|SEVERE|sun-appserver-pe8.0.0_01|javax.enterpris e.system.container.web|_ThreadID=13;|StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: Null primary key returned by ejbCreate method
at com.sun.corba.ee.impl.javax.rmi.CORBA.Util.wrapException(Util.java:597)
at javax.rmi.CORBA.Util.wrapException(Util.java:277)
at com.forum.ejb._ForumHome_Stub.create(Unknown Source)
at org.apache.jsp.test.testForum_jsp._jspService(testForum_jsp.java:54)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:102)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:282)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:263)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:210)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:861)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.ja va:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:246)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:499)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFil terChain.java:236)
at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterCha in.java:55)
at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.ja va:145)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:141)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java: 220)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextVal ve.java:214)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java: 168)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:144)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:133)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:539)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.webservice.EjbWebServiceValve.invoke(EjbWebServiceValve.java :134)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.security.web.SingleSignOn.invoke(SingleSignOn.java:254)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at com.sun.enterprise.web.VirtualServerValve.invoke(VirtualServerValve.java:209)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:11 4)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:109)
at com.sun.enterprise.web.VirtualServerMappingValve.invoke(VirtualServerMappingVal ve.java:166)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.j ava:107)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:522)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:936)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:165)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:683)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnecti on(Http11Protocol.java:604)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:542)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:6 47)
at java.lang.Thread.run(Thread.java:536)
Caused by: java.rmi.RemoteException: Null primary key returned by ejbCreate method

By Entity bean is

/*
* ForumBean.java
*
* Created on January 31, 2005, 12:56 PM
*/

package com.forum.ejb;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;

import java.sql.Date;

import com.forum.ForumException;

/**
*
* @author suneesh.raman
*/
abstract public class ForumBean implements EntityBean
{
private EntityContext ctx;
abstract public Integer getForumId ();
abstract public void setForumId (Integer forumId);
abstract public String getForumTitle ();
abstract public void setForumTitle (String forumTitle);
abstract public String getForumDesc ();
abstract public void setForumDesc (String desc);
abstract public Date getCreationDate ();
abstract public void setCreationDate (Date date);
abstract public Date getUpdationDate ();
abstract public void setUpdationDate (Date date);
abstract public int getUserId ();
abstract public void setUserId (int userId);

public void updateForum (String forumTitle,String forumDesc,int userId,Date date )
{
setForumTitle (forumTitle);
setForumDesc (forumDesc);
setUserId (userId);
setCreationDate (date);
setUpdationDate (new Date (new java.util.Date ().getTime ()));
}
public Integer ejbCreate (String forumTitle, String forumDesc, int userId) throws CreateException
{
setForumTitle (forumTitle);
setForumDesc (forumDesc);
setUserId (userId);
setCreationDate (new Date (new java.util.Date ().getTime ()));
setUpdationDate (new Date (new java.util.Date ().getTime ()));
return new Integer(0);
}
public int forumId ()
{
return getForumId ().intValue ();
}
public String forumTitle ()
{
return getForumTitle ();
}
public String forumDesc ()
{
return getForumDesc ();
}
public Date creationDate ()
{
return getCreationDate ();
}
public Date updationDate ()
{
return getUpdationDate ();
}
public int userId ()
{
return getUserId ();
}
public void ejbPostCreate (String forumTitle,String forumDesc,int userId)
{
System.out.println("Inside ejbPostCreate...");
}
public void ejbActivate () throws javax.ejb.EJBException, java.rmi.RemoteException
{
System.out.println("Inside ejbActivate...");
}

public void ejbLoad () throws javax.ejb.EJBException, java.rmi.RemoteException
{
System.out.println("Inside ejbLoad...");
}

public void ejbPassivate () throws javax.ejb.EJBException, java.rmi.RemoteException
{
System.out.println("Inside Passivate ...");
}

public void ejbRemove () throws javax.ejb.RemoveException, javax.ejb.EJBException, java.rmi.RemoteException
{
System.out.println("Inside ejbRemove...");
}

public void ejbStore () throws javax.ejb.EJBException, java.rmi.RemoteException
{
System.out.println("Inside ejbStore...");
}

public void setEntityContext (javax.ejb.EntityContext entityContext) throws javax.ejb.EJBException, java.rmi.RemoteException
{
this.ctx= entityContext;
}

public void unsetEntityContext () throws javax.ejb.EJBException, java.rmi.RemoteException
{
this.ctx=null;
}


}
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Suneesh VR:
javax.ejb.EJBException: Null primary key returned by ejbCreate method
...
What a strange error message. The EJB spec requires that you return null from ejbCreate in this case. Change that last line to "return null". I suspect that the container is getting confused by you returning a non-null value.
 
Suneesh Raman
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried with null value also . But the problem was I am not setting the primary key . I thought the primary key will generated qutomatically since the primary key was the auto number . I used am ejbSelect and writtent he QL for getting the auto number and it solved the problem

Thanks
Suneesh
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to tell the EJB container that you're using an auto-generated primary key. I'm not sure if yours will work with MySQL's autonumber column. For example, in WebLogic I gave it the name of an Oracle sequence and it handles setting the PK for me, doing pretty much what you did but with only a line or two of XML on my part.

In the end it's the same thing, so I'd stick with that works in your case.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!