I am having a problem while creating an entity of a related table (I'm using MS SQL Server and Enterprise Application in NetBeans IDE 7.2 - EJB3)
My database includes:
- Projects table: primary key: projectId (int)
- Users table: primary key: username (String)
- UserProject table:
- projectId (FK reference table Projects)
- username (FK reference table Users)
- ... and some other field ...
- primary key: projectId and username (double PK)
When I create entity classes from Database, the class UserProjectPK is automatically created. Here is the class UserProject:
public class UserProject implements Serializable {
@JoinColumn(name = "projectId", referencedColumnName = "projectId", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Projects projects;
@JoinColumn(name = "invitedLeader", referencedColumnName = "username")
@ManyToOne
private Users invitedLeader;
@JoinColumn(name = "username", referencedColumnName = "username", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Users users;
private static final long serialVersionUID = 1L;
@EmbeddedId
protected UserProjectPK userProjectPK;
@Size(max = 30)
@Column(name = "position")
private String position;
@Column(name = "startDate")
@Temporal(TemporalType.TIMESTAMP)
private Date startDate;
@Basic(optional = false)
@NotNull
@Column(name = "confirmed")
private boolean confirmed;
//getter and setter function
I tried to create a new UserProject entity in UserProjectFacade (Session bean for Entity class):
public boolean join(Projects project, Users user, Users invitedLeader, String position, Date startDate) {
UserProject newUserProject = new UserProject();
UserProjectPK newUserProjectPK = new UserProjectPK(user.getUsername(), project.getProjectId());
newUserProject.setUserProjectPK(newUserProjectPK);
newUserProject.setProjects(project);
newUserProject.setUsers(user);
newUserProject.setInvitedLeader(invitedLeader);
newUserProject.setPosition(position);
newUserProject.setStartDate(startDate);
if (invitedLeader == user) {
newUserProject.setConfirmed(true);
} else {
newUserProject.setConfirmed(false);
}
try {
create(newUserProject);
return true;
} catch (Exception e) {}
return false;
}
And when I run the function, the GlassFish Server reports the following errors:
WARNING: EJB5184:A system exception occurred during an invocation on EJB UserProjectFacade, method: public boolean ass2.session.UserProjectFacade.join(ass2.entity.Projects,ass2.entity.Users,ass2.entity.Users,java.lang.String,java.util.Date)
WARNING: javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5215)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5113)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4901)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:89)
at $Proxy379.join(Unknown Source)
at ass2.UserProjectSessionStub.join(UserProjectSessionStub.java:35)
at org.apache.jsp.createProject_jsp._jspService(createProject_jsp.java:118)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at ass2.session.UserProjectFacade.join(UserProjectFacade.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:144)
at sun.reflect.GeneratedMethodAccessor97.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:214)
... 34 more
I'm new to EJB3 so I don't know how to handle this. Please help me (asap). Thank you a lot!