Problem while accessing the CMP(oracle)
bonthus Dec 8, 2004 10:21 AMI was deployed one CMP in JBOSS 3.2.5 it got deployed while accesing that BEAN it is throwing exception saying as 'null value was got for one attribute but it should not be'.
actually i was developed a CMP for employee table which was there in ORACLE database
my home interface is like as below
package com.ness.training.ejb;
import javax.ejb.EJBHome;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
public interface EmployeeEntityHome extends EJBHome
{
public EmployeeEntity create(java.lang.Integer empID,String eName,String designation) throws CreateException,RemoteException;
public EmployeeEntity findByPrimaryKey(Integer key) throws RemoteException,FinderException;
public java.util.Collection findAll()throws RemoteException,FinderException;
}
my remote interface was like as below
package com.ness.training.ejb;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface EmployeeEntity extends EJBObject
{
public Integer getEmpID() throws RemoteException;
public String getEName() throws RemoteException;
public String getDesignation() throws RemoteException;
public void setEmpID(Integer ent) throws RemoteException;
public void setEName(String eName) throws RemoteException;
public void setDesignation(String designation) throws RemoteException;
}
My Bean class as like as below
package com.ness.training.ejb;
import javax.ejb.CreateException;
import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
public abstract class EmployeeEntityBean implements EntityBean
{
private transient EntityContext entContext;
public Integer empID;
public String eName;
public String designation;
public void setEntityContext(EntityContext context){
System.out.println("now it was in setEntityContext method");
entContext = context;
}
public void unsetEntityContext(){
entContext = null;
}
public Integer ejbCreate(Integer empid , String ename , String design) throws CreateException{
this.empID =empid;
this.eName = "bvn";
this.designation = "se";
System.out.println("inside bean method"+empid);
return this.empID;
}
public void ejbPostCreate(Integer empid,String ename , String design){
System.out.println("in side ejb post create method "+empid);
}
public void ejbActivate(){
}
public void ejbPassivate(){
}
public void ejbRemove(){
}
public void ejbLoad(){
}
public void ejbStore(){
}
public abstract Integer getEmpID();
public abstract String getEName();
public abstract String getDesignation();
public abstract void setEName(String ename);
public abstract void setDesignation(String design);
public abstract void setEmpID(Integer ent);
}
my ejb-jar.xml is like as below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<!-- Generated XML! -->
<ejb-jar>
<enterprise-beans>
<ejb-name>FirstSessionBean</ejb-name>
com.ness.training.ejb.FirstSessionHome
com.ness.training.ejb.FirstSession
<ejb-class>com.ness.training.ejb.FirstSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<!-- <resource-ref>
<res-ref-name>OracleDS</res-ref-name>
<res-type>java.sql.DataSource</res-type>
<res-auth>Container</res-auth>
Data source for oracle
</resource-ref>-->
<ejb-name>EmployeeCMP</ejb-name>
com.ness.training.ejb.EmployeeEntityHome
com.ness.training.ejb.EmployeeEntity
<ejb-class>com.ness.training.ejb.EmployeeEntityBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-version>1.x</cmp-version>
<abstract-schema-name>Employee</abstract-schema-name>
<cmp-field><field-name>empID</field-name></cmp-field>
<cmp-field><field-name>eName</field-name></cmp-field>
<cmp-field><field-name>designation</field-name></cmp-field>
<primkey-field>empID</primkey-field>
</enterprise-beans>
</ejb-jar>
my jbosscmp-jdbc-oracle.xml is like as below
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<!-- Generated XML! -->
<ejb-jar>
<enterprise-beans>
<ejb-name>FirstSessionBean</ejb-name>
com.ness.training.ejb.FirstSessionHome
com.ness.training.ejb.FirstSession
<ejb-class>com.ness.training.ejb.FirstSessionBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<!-- <resource-ref>
<res-ref-name>OracleDS</res-ref-name>
<res-type>java.sql.DataSource</res-type>
<res-auth>Container</res-auth>
Data source for oracle
</resource-ref>-->
<ejb-name>EmployeeCMP</ejb-name>
com.ness.training.ejb.EmployeeEntityHome
com.ness.training.ejb.EmployeeEntity
<ejb-class>com.ness.training.ejb.EmployeeEntityBean</ejb-class>
<persistence-type>Container</persistence-type>
<prim-key-class>java.lang.Integer</prim-key-class>
False
<cmp-version>1.x</cmp-version>
<abstract-schema-name>Employee</abstract-schema-name>
<cmp-field><field-name>empID</field-name></cmp-field>
<cmp-field><field-name>eName</field-name></cmp-field>
<cmp-field><field-name>designation</field-name></cmp-field>
<primkey-field>empID</primkey-field>
</enterprise-beans>
</ejb-jar>
client code for this entity bean is like as below
com.ness.training.ejb.EmployeeEntityHome home = (com.ness.training.ejb.EmployeeEntityHome)ctx.lookup("EmployeeCMP");
//Collection total = home.findAll();
com.ness.training.ejb.EmployeeEntity bean = home.create( new Integer(2),"bvn","SE");
information at console after starting the server
20:36:26,908 INFO [EARDeployer] Init J2EE application: file:/C:/jboss-3.2.5/server/default/deploy/ejbdeploy.ear
20:36:27,221 INFO [EjbModule] Deploying EmployeeCMP
20:36:27,768 INFO [EjbModule] Deploying FirstSessionBean
20:36:30,002 INFO [EmployeeCMP] Table 'EMPLOYEE' already exists
20:36:30,049 INFO [EJBDeployer] Deployed: file:/C:/jboss-3.2.5/server/default/tmp/deploy/tmp47781ejbdeploy.ear-contents/ejbtraining.jar
20:36:30,143 INFO [EARDeployer] Started J2EE application: file:/C:/jboss-3.2.5/server/default/deploy/ejbdeploy.ear
20:36:30,143 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
Packages waiting for a deployer:
org.jboss.deployment.DeploymentInfo@2445cf14 { url=file:/C:/jboss-3.2.5/server/default/deploy/jbosscmp-jdbc-oracle.xml }
deployer: null
status: null
state: INIT_WAITING_DEPLOYER
watch: file:/C:/jboss-3.2.5/server/default/deploy/jbosscmp-jdbc-oracle.xml
lastDeployed: 1102518390143
lastModified: 1102518390143
mbeans:
Incompletely deployed packages:
org.jboss.deployment.DeploymentInfo@2445cf14 { url=file:/C:/jboss-3.2.5/server/default/deploy/jbosscmp-jdbc-oracle.xml }
deployer: null
status: null
state: INIT_WAITING_DEPLOYER
watch: file:/C:/jboss-3.2.5/server/default/deploy/jbosscmp-jdbc-oracle.xml
lastDeployed: 1102518390143
lastModified: 1102518390143
mbeans:
20:36:30,252 INFO [Server] JBoss (MX MicroKernel) [3.2.5 (build: CVSTag=JBoss_3_2_5 date=200406251954)] Started in 19s:843ms
20:36:30,252 INFO [Tomcat5] Saw org.jboss.system.server.started notification, starting connectors
20:36:30,330 INFO [Http11Protocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
20:36:30,502 INFO [ChannelSocket] JK2: ajp13 listening on /0.0.0.0:8009
20:36:30,518 INFO [JkMain] Jk running ID=0 time=0/94 config=null
error coming at server side after running the client java class
20:38:36,296 INFO [STDOUT] now it was in setEntityContext method
20:38:36,311 INFO [STDOUT] inside bean method2
20:38:36,358 ERROR [EmployeeCMP] Could not create entity
java.sql.SQLException: ORA-01400: cannot insert NULL into ("SYSTEM"."EMPLOYEE"."EMPID")
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:180)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:542)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2887)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2959)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:335)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.executeInsert(JDBCAbstractCreateCommand.java:328)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:286)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:137)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:562)
at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:203)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269)
at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:725)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1061)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:204)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:214)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:90)
at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:128)
at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:94)
at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:478)
at org.jboss.ejb.Container.invoke(Container.java:743)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
information in log file
2004-12-08 20:38:36,296 INFO [STDOUT] now it was in setEntityContext method
2004-12-08 20:38:36,311 INFO [STDOUT] inside bean method2
2004-12-08 20:38:36,311 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.EmployeeCMP] Executing SQL: SELECT COUNT(*) FROM EMPLOYEE WHERE empid=?
2004-12-08 20:38:36,343 DEBUG [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.EmployeeCMP] Executing SQL: INSERT INTO EMPLOYEE (empid, ename, designation) VALUES (?, ?, ?)
2004-12-08 20:38:36,358 ERROR [org.jboss.ejb.plugins.cmp.jdbc.JDBCCreateEntityCommand.EmployeeCMP] Could not create entity
java.sql.SQLException: ORA-01400: cannot insert NULL into ("SYSTEM"."EMPLOYEE"."EMPID")
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:124)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:304)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:271)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:622)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:180)
at oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStatement.java:542)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1027)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2887)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:2959)
at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.executeUpdate(WrappedPreparedStatement.java:335)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.executeInsert(JDBCAbstractCreateCommand.java:328)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.performInsert(JDBCAbstractCreateCommand.java:286)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:137)
at org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:562)
at org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:203)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:269)
at org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:725)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:1061)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:204)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:214)
at org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:90)
at org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
at org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:315)
at org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:128)
at org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:94)
at org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
at org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:478)
at org.jboss.ejb.Container.invoke(Container.java:743)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.server.ReflectedDispatcher.dispatch(ReflectedDispatcher.java:60)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:61)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:53)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:185)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:473)
at org.jboss.invocation.jrmp.server.JRMPInvoker.invoke(JRMPInvoker.java:360)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:536)
though i am sending a valid value(2) it is showing some null value was reached
can any body help me about this