Hi all,

I using beta prod3 (the same problem was and with prod2)

I have EntiryBean ejbCreate function where i inserting data into oracle by name (inVCCName)
I have constraint on the table and it allows just unique names
Currently running version (Weblogic) thows SQLException where i can check if not unique name i was trying to insert.
first function call ::ejbCreate ("XXX", "Notes1") works fine

second call of ::ejbCreate ("XXX", "Notes2") works strange:
I catch java.sql.SQLException and i want to throw my DuplicateVCCNameException but instead of it i do getting TRANSACTION ROLLBACK EXCEPTION

Why it is so?

One of my possible bugs gan be here:
int aSeqId = getNextSeqID("VCCSeqIdSequence") // gets oracle connection using getConnection() function
later in the create function i do getting another con = getConnection();

As i undersand i should get the same connection for the same EBJ transaction (::ejbCreate is bean bean function with MANDATORY transaction atribute).

BTW this functions was working fine under Weblogic



logs from jBossServer:

[[VCC] VCCBean::ejbCreate(...)
[VCC] BaseBeanFunctions::setModified()
[VCC] Getting seq ID
[VCC] 32
[VCC] getting connection...
[VCC] got connection
[VCC] Primary key created
[VCC] Statment prepared
[VCC] Parameters binded
[VCC] VCCBean::ejbCreate(...) exc: java.sql.SQLException: ORA-00001: unique cons
traint (DDD.U_VCCS_NAME) violated
[VCC] I'm here
[VCC] TRANSACTION ROLLBACK EXCEPTION:id may not be null; nested exception is:
java.lang.Error: id may not be null
[VCC] java.lang.Error: id may not be null

/**
Here is my ejbCreate function
*/
public VirtualCallCenterPK ejbCreate( String inVCCName,
String inNotes
)
throws CreateException, DuplicateVCCNameException

{
log("VCCBean::ejbCreate(...)",theLogLevel );


theVCCName = inVCCName;
theNotes = inNotes;

setModified(true);


Connection con = null;
PreparedStatement ps = null;
try
{

log("Getting seq ID",theLogLevel );
int aSeqId = getNextSeqID("VCCSeqIdSequence");
log(aSeqId,theLogLevel );

log("getting connection...",theLogLevel );
con = getConnection();
log("got connection",theLogLevel );


thePK = new VirtualCallCenterPK( aSeqId );

log("Primary key created",theLogLevel );
ps = con.prepareStatement(
"insert into VCCs"
+" (VCCSeqId, name, notes)"
+" values (?,?,?)");

log("Statment prepared",theLogLevel );
ps.setInt(1, thePK.getSeqId());
ps.setString(2, theVCCName);
ps.setString(3, theNotes);
log("Parameters binded",theLogLevel );

if (ps.executeUpdate() != 1) {
String error = "0 records inserted.";
throw new Exception (error);
}
log("VCC create - OK",theLogLevel );
}
catch (SQLException sqe)
{
String error = "VCCBean::ejbCreate(...) exc: " + sqe;
log(error,theLogLevel );
if ( sqe.getErrorCode() == 1 &&
sqe.toString().indexOf(UNIQUE_VCC_NAME) != -1)
{
log("I'm here",theLogLevel );
error = "VCCBean::ejbCreate: Name- " + inVCCName+" already exist.";
throw new DuplicateVCCNameException (error);
}
else throw new EJBException (error);

}
catch (Exception sqe)
{
String error = "VCCBean::ejbCreate(...) exc: " + sqe;
log(error,1);
throw new CreateException (error);
}
finally
{
cleanup(con,ps);
}
return thePK;

}

/**
gets new sequance ID from the oracle.
Sequance name should be passed like parameter
*/
protected int getNextSeqID(String inSeqName) throws SQLException
{
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;

try
{
con = getConnection();
ps = con.prepareStatement( "select " +
inSeqName +
".nextVal from dual" );

rs = ps.executeQuery();

if (rs.next()) {
return rs.getInt(1);
}
else
{
throw new EJBException();
}

}
catch (Exception sqe)
{
String error = "BaseBeanFunctions::getNextSeqID() : " + sqe;
throw new EJBException (error);
}
finally
{
rs.close();
cleanup(con,ps);
}
}

/**
My function for getting connection from oracle pool
*/
protected Connection getConnection()
throws SQLException
{
InitialContext initCtx = null;
try {
initCtx = new InitialContext();
DataSource ds = null;
Connection aCon = null;
ds = (javax.sql.DataSource)initCtx.lookup("java:comp/env/jdbc/OraclePool");
aCon = ds.getConnection();
return aCon;

} catch(NamingException ne) {
log("UNABLE to get a connection from oraclePool!", theLogLevel);
log("Please make sure that you have setup the connection pool properly",theLogLevel);
throw new EJBException(ne);
} finally {
try {
if(initCtx != null) initCtx.close();
} catch(NamingException ne) {
log("Error closing context: " + ne, theLogLevel);
throw new EJBException(ne);
}
}
}

/**
Here is how my table is created
*/
CREATE TABLE VCCs
(
VCCSeqId INTEGER NOT NULL,
name VARCHAR(32) NOT NULL,
notes VARCHAR(256),
CONSTRAINT PK_VCCs PRIMARY KEY (VCCSeqId),
CONSTRAINT U_VCCs_name UNIQUE (name)
);


Any sugestions wellcome
Darius Davidavicius



Reply via email to