• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

BMP Entity will not insert a null value into db field that allows nulls

Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ladies And Gentlemen;
I have a BMP Entity Bean wrapped by a session bean that upon creation, inserts a record into the db. When inserting non null values for an int (Java Integer) into the field the insert is successfull. However, when inserting nulls for both the int field and the char field, an exception is thrown (included below). Inserting an int value and a null into the char field is successfull. It is only the int field that has a problem with the null value insert. I am using java.lang.Integer to represent this field.

The jdbc code to do this insert uses the setNull method of PreparedStatement class to do the insert. This code, when modified to change the connection source, does do the insert sucessfully from a stand alone client.

The local home and component interfaces for this entity bean are:

public interface TimeAccountHomeLocal extends EJBLocalHome
public TimeAccountLocal create(int employeeNum, Integer serverNum,
String instance, String date, int mworked, int clientDescNum) throws CreateException;
public TimeAccountLocal findByPrimaryKey(Integer primaryKey) throws FinderException;

public interface TimeAccountLocal extends EJBLocalObject
public int getEmployeeNum() ;
public Integer getServerNum() ;
public String getInstanceName() ;
public String getDate() ;
public int getMinutesWorked() ;
public int getClientDescNum() ;
public void setEmployeeNum(int employeeNum);
public void setServerNum(Integer serverNum);
public void setInstanceName(String instance);
public void setDate(String date);
public void setMinutesWorked(int minutesWorked);
public void setClientDescNum(int descNum);
The EJBCreate() of the BMP Entity:
public Integer ejbCreate(int employeeNum,Integer serverNum ,String instanceName,
String date, int minutesWorked , int clientDescNum )
throws CreateException
this.employeeNum = employeeNum;
this.serverNum = serverNum;
this.instanceName = instanceName;
this.minutesWorked = minutesWorked;
this.date = date;
this.clientDescNum = clientDescNum;
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
con = this.getConnection();
System.out.println("Obtained Connection: Trying to create statement");
if (this.getServerNum() != null && this.getServerNum().intValue() >= 0)
ps = con.prepareStatement("insert into timeAccount"+""+ " values (?,?,?,?,?,?)");
ps.setInt(1, this.getEmployeeNum());
int iServerNum = this.getServerNum().intValue();
if ( iServerNum >= 1)
ps.setInt(2, iServerNum);
ps.setNull(2 , Types.NUMERIC);
if (this.getInstanceName() != null)
ps.setString(3, this.getInstanceName());
ps.setNull(3 , Types.CHAR);
ps.setString(4, this.getDate());
ps.setInt(5, this.getMinutesWorked());
ps.setInt(6, this.clientDescNum);
ps = con.prepareStatement("insert into timeAccount"+""+ " values (?,null,?,?,?,?)");
ps.setInt(1, this.getEmployeeNum());
if (this.getInstanceName() != null)
ps.setString(2, this.getInstanceName());
ps.setNull(2 , Types.CHAR);
ps.setString(3, this.getDate());
ps.setInt(4, this.getMinutesWorked());
ps.setInt(5, this.clientDescNum);
// ps.setObject(2, null, Types.NUMERIC);
// ps.setString(2 , "null");

if (ps.executeUpdate() != 1)
throw new CreateException ("Failed to add Record to database");
ps = con.prepareStatement("select @@identity as NewRec");
rs = ps.executeQuery();
recNum = new Integer(rs.getInt("NewRec"));
// String strSQL = " Update timeAccount set server# = null where server# = 1";
// ps = con.prepareStatement(strSQL);
// if (ps.executeUpdate() != 1)
// {
// throw new CreateException ("Failed to modify database record");
// }
// else
// {
// System.out.println("Update Executed. SQL => "+strSQL );
// }
return recNum;
catch (SQLException se) {
throw new EJBException (se);
finally {
try {
if (ps != null) ps.close();
if (con!= null) con.close();
} catch(SQLException se) {

Any assistance is appreciated.
The exception stack trace follows.

John Olmstead

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.RemoteException: Transaction aborted (possibly due to transaction time out).; nested exception is: javax.transaction.RollbackException; nested exception is:
at com.sun.corba.ee.internal.iiop.ShutdownUtilDelegate.mapSystemException(ShutdownUtilDelegate.java:64)
at javax.rmi.CORBA.Util.mapSystemException(Util.java:65)
at dbadirect.administration.timekeeping.session._TimeAccountManage_Stub.insertTimeAccount(Unknown Source)
at ejbClient.TimeAccountClient.insertBeanRecord(TimeAccountClient.java:113)
at ejbClient.TimeAccountClient.main(TimeAccountClient.java:44)
Caused by: java.rmi.RemoteException: Transaction aborted (possibly due to transaction time out).; nested exception is: javax.transaction.RollbackException; nested exception is:
at com.sun.enterprise.iiop.POAProtocolMgr.mapException(POAProtocolMgr.java:389)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:431)
at dbadirect.administration.timekeeping.session.TimeAccountManageBean_EJBObjectImpl.insertTimeAccount(TimeAccountManageBean_EJBObjectImpl.java:44)
at dbadirect.administration.timekeeping.session._TimeAccountManageBean_EJBObjectImpl_Tie._invoke(Unknown Source)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatchToServant(GenericPOAServerSC.java:520)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.internalDispatch(GenericPOAServerSC.java:210)
at com.sun.corba.ee.internal.POA.GenericPOAServerSC.dispatch(GenericPOAServerSC.java:112)
at com.sun.corba.ee.internal.iiop.ORB.process(ORB.java:255)
at com.sun.corba.ee.internal.iiop.RequestProcessor.process(RequestProcessor.java:84)
at com.sun.corba.ee.internal.orbutil.ThreadPool$PooledThread.run(ThreadPool.java:99)
Caused by: javax.transaction.RollbackException
at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:210)
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(J2EETransactionManagerOpt.java:245)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:1485)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:1289)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:403)
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic