This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

Posts: 6
  • Mark post as helpful
  • send pies
  • 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; = 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 javax.rmi.CORBA.Util.mapSystemException(
at dbadirect.administration.timekeeping.session._TimeAccountManage_Stub.insertTimeAccount(Unknown Source)
at ejbClient.TimeAccountClient.insertBeanRecord(
at ejbClient.TimeAccountClient.main(
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(
at com.sun.ejb.containers.BaseContainer.postInvoke(
at dbadirect.administration.timekeeping.session.TimeAccountManageBean_EJBObjectImpl.insertTimeAccount(
at dbadirect.administration.timekeeping.session._TimeAccountManageBean_EJBObjectImpl_Tie._invoke(Unknown Source)
Caused by: javax.transaction.RollbackException
at com.sun.jts.jta.TransactionManagerImpl.commit(
at com.sun.enterprise.distributedtx.J2EETransactionManagerOpt.commit(
at com.sun.ejb.containers.BaseContainer.completeNewTx(
at com.sun.ejb.containers.BaseContainer.postInvokeTx(
at com.sun.ejb.containers.BaseContainer.postInvoke(
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!