Help coderanch get a
new server
by contributing to the fundraiser

John Olmstead

Greenhorn
+ Follow
since Nov 25, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Olmstead

Thank you for your replies. I have tried both stmt.execute() and stmt.executeUpdate(). Both hang. I am executing this code from a testcase for this dao.

I will be looking at alternative JDBC drivers next week.

Thanks;

John Olmstead
Hello Collegues;

Oracle 9i procedure Called From hibernateDAOTestCase
1.4.2_05 jdk

The code snippet below hangs ( No Stacktrace) on the executeUpdate method call on a CallableStatement Object. All hibernate dao calls unrelated to stored procedures work well. Any comments or assistance is appreciated!


public void add( Job job)
{
Session s = null;
Connection conn = null;
String oracleQuery = "BEGIN MPCS.JOB_PRE_INSERT(:1 , :2); END;";
try
{
s = this.getHibernateTemplate().getSessionFactory().openSession();
conn = s.connection();
CallableStatement stmt = conn.prepareCall(oracleQuery);
stmt.registerOutParameter(1, OracleTypes.VARCHAR);
stmt.registerOutParameter(2, OracleTypes.NUMBER);
// <== Hangs Here ==>
stmt.executeUpdate();

log.info("Variable1 : "+stmt.getString(1));
log.info("Variable2 : "+stmt.getBigDecimal(2));

}

catch(HibernateException he)
{
log.warn(he.getMessage() , he);
}
catch(SQLException sqle)
{
log.warn(sqle.getMessage() , sqle);
}
finally
{
try
{
s.close();
}
catch(HibernateException he){log.warn(he.getMessage() , he);}
}


}

There is no stack trace and the Hibernate/JDBC calls work very well from the rest of the class.

Here is the stored procedure, which does work from my sql client :

newjob OUT MPCS.JOB.JOB_NO%TYPE,
cnum OUT MPCS.TEXT.CONTROL_NUM%TYPE)
AS
-- MPCS.JOB - PRE-INSERT STORED PROCEDURE - GETS NEXT JOB#.
-- CREATED 06-OCT-2004 SAB.

pre_ins_err EXCEPTION;
exit_wo_err EXCEPTION;
err_mess VARCHAR2(100);
asciijl MPCS.COSTCONTROL.ASCII_JOB_LETTER%TYPE;
jobno MPCS.COSTCONTROL.JOB_NUMBER%TYPE;
njcol1 MPCS.COSTCONTROL.NEWJOB_COL1%TYPE;
njcol2 MPCS.COSTCONTROL.NEWJOB_COL2%TYPE;
njcol3 MPCS.COSTCONTROL.NEWJOB_COL3%TYPE;
njcol45 MPCS.COSTCONTROL.NEWJOB_COL45%TYPE;
job4char MPCS.JOB.JOB_NO%TYPE;
job5char MPCS.JOB.JOB_NO%TYPE;
BEGIN
LOCK TABLE MPCS.CONTROL_NUM, MPCS.COSTCONTROL
IN SHARE UPDATE MODE;

-- Get the general job text primary key control number.
UPDATE MPCS.CONTROL_NUM
SET CONTROL_NUM = CONTROL_NUM + 1
WHERE CONTROL_NUM_TYPE = 'TEXT';
IF SQL%NOTFOUND THEN
err_mess := 'System error incrementing text control number.';
RAISE pre_ins_err;
END IF;

err_mess := 'System error retrieving next text control number.';
SELECT CONTROL_NUM INTO cnum
FROM MPCS.CONTROL_NUM
WHERE CONTROL_NUM_TYPE = 'TEXT';

-- Get the information to create the next job number.
err_mess := 'System error getting next job number.';
SELECT ASCII_JOB_LETTER, NEWJOB_COL1, CHR(ASCII_JOB_LETTER)||LTRIM(TO_CHAR(JOB_NUMBER,'009')),
CHR(NEWJOB_COL1)||LTRIM(TO_CHAR(NEWJOB_COL2,'9'))||CHR(NEWJOB_COL3)||LTRIM(TO_CHAR(NEWJOB_COL45,'09')),
JOB_NUMBER, NEWJOB_COL2, NEWJOB_COL3, NEWJOB_COL45
INTO asciijl, njcol1, job4char, job5char, jobno, njcol2, njcol3, njcol45
FROM MPCS.COSTCONTROL;

-- IF ORIGINAL JOB LETTER IS 'Z', UPDATE NEW JOB FORMAT FOR NEXT JOB CREATE.
IF asciijl < 90 THEN
newjob := job4char;
-- Add 1 to number counter...max 999.
IF jobno < 999 THEN
jobno := jobno + 1;
ELSIF jobno >= 999 THEN
-- Add 1 to letter counter.
asciijl := asciijl + 1;
-- Skip I and O and Q and S and X.
IF asciijl IN (73, 79, 81, 83, 88) THEN asciijl := asciijl + 1; END IF;
jobno := 1;
END IF;
ELSIF njcol1 < 90 THEN
-- NEW JOB FORMAT: A thru Y , 0 thru 9 , A thru Y , 01 thru 99. - 5 characters total: A0A01 will be the first. 396,000 combinations.
-- Skip I, O, Q, S, X, Z for letter characters.
newjob := job5char;
IF njcol45 < 99 THEN
njcol45 := njcol45 + 1;-- Increase to next number.
ELSE
njcol45 := 1;-- Set back to 01.
njcol3 := njcol3 + 1;-- Increase to next letter.
-- If 3rd character = Z, set back to A and increase 2nd character.
IF njcol3 = 90 THEN
njcol3 := 65;-- Set back to letter A.
njcol2 := njcol2 + 1;-- Increase to next number.
-- If 2nd character > 9, set back to 0 and increase 1st character.
IF njcol2 > 9 THEN
njcol2 := 0;-- Set back to 0.
njcol1 := njcol1 + 1;-- Increase to next letter.
-- If I, O, Q, S, or X, add 1 to letter.
IF njcol1 IN (73, 79, 81, 83, 88) THEN njcol1 := njcol1 + 1; END IF;
END IF;
ELSE
-- If I, O, Q, S, or X, add 1 to letter.
IF njcol3 IN (73, 79, 81, 83, 88) THEN njcol3 := njcol3 + 1; END IF;
END IF;
END IF;
ELSE
err_mess := 'The maximum job number has already been used. Call System Manager.';
RAISE pre_ins_err;
END IF;

-- Store next job number.
UPDATE MPCS.COSTCONTROL SET JOB_NUMBER = jobno,
ASCII_JOB_LETTER = asciijl,
NEWJOB_COL1 = njcol1,
NEWJOB_COL2 = njcol2,
NEWJOB_COL3 = njcol3,
NEWJOB_COL45 = njcol45;

EXCEPTION
WHEN pre_ins_err THEN
RAISE_APPLICATION_ERROR(-20005, err_mess);
WHEN exit_wo_err THEN
RAISE_APPLICATION_ERROR(-20000, 'Quit without error message.');
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20005, err_mess);
WHEN OTHERS THEN
RAISE;
END JOB_PRE_INSERT;
Gentlemen;

I have reviewed your Hibernate 3.0 alpha and am glad you are adding support for stored procedures. However, in our Oracle environment, legacy stored procedures are used for a wide variety of activities other than the CUD that you seem to support.

Will you be supporting procedure calls that return result sets, that may, or may not map to a specific configuration? Will I be limited to getting a connection from the hibernate session and executng native jdbc to get at these procedures? This seems to defeat the whole concept of object mapping.

I appreciate your efforts and comments.

Thank You;

John Olmstead
I would like to use our primary Tomcat Web container to access ejb resources from an application server running remotely on a seperate box. In order for classes in the web container to function as an ejb client, classes from the j2ee.jar file are required. However, this jar has classes of the same signature from the javax.Servlet package in the Servlet.jar file and the relevent Servlet Spec prohibits this.

Error logging reports the following :

WebappClassLoader: validateJarFile(C:\Tomcat4\webapps\ems\WEB-INF\lib\j2ee.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class

The referenced Servlet specification is :

SRV.9.7.2 Web Application Classloader
The classloader that a container uses to load a servlet in a WAR must allow thedeveloper to load any resources contained in library JARs within the WARfollowing normal J2SE semantics using getResource. It must not allow theWAR tooverride J2SE or Java servlet API classes. It is further recommended that the loadernot allow servlets in theWAR access to the web container’s implementation classes.It is recommended also that the application class loader be implemented sothat classes and resources packaged within the WAR are loaded in preference toclasses and resources residing in container-wide library JARs.

Clearly, both of these jars cannot be in the classpath. So the question is, what is the standard practice for accessing J2EE applications from remote web clients?
Much Thanks and Appreciation;
John Olmstead
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;
try
{
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);
else
ps.setNull(2 , Types.NUMERIC);
if (this.getInstanceName() != null)
ps.setString(3, this.getInstanceName());
else
ps.setNull(3 , Types.CHAR);
ps.setString(4, this.getDate());
ps.setInt(5, this.getMinutesWorked());
ps.setInt(6, this.clientDescNum);
}
else
{
ps = con.prepareStatement("insert into timeAccount"+""+ " values (?,null,?,?,?,?)");
ps.setInt(1, this.getEmployeeNum());
if (this.getInstanceName() != null)
ps.setString(2, this.getInstanceName());
else
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();
rs.next();
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) {
se.printStackTrace();
}
}
}

Any assistance is appreciated.
The exception stack trace follows.

Thanks;
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:
javax.transaction.RollbackException
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:
javax.transaction.RollbackException
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)

Originally posted by Kathy Sierra:
Howdy -- I thought I'd start a new topic on this rather than add to the old one.
Some people have been getting this incredibly helpful and enlightening CORBA.BAD_OPERATION error when they run the AdviceClient client on the J2EE 1.3 RI, at the point where the business method (getAdvice()) is invoked:

org.omg.CORBA.BAD_OPERATION: minor code: 0 completed: No
org.omg.CORBA.BAD_OPERATION: minor code: 0 completed: No
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:232)
at com.sun.corba.ee.internal.iiop.messages.ReplyMessage_1_2.getSystemExc
eption(ReplyMessage_1_2.java:93)
at com.sun.corba.ee.internal.iiop.ClientResponseImpl.getSystemException(
ClientResponseImpl.java:108)
at com.sun.corba.ee.internal.POA.GenericPOAClientSC.invoke(GenericPOACli
entSC.java:132)
at org.omg.CORBA.portable.ObjectImpl._invoke(ObjectImpl.java:454)
at headfirst._Advice_Stub.getAdvice(Unknown Source)
at AdviceClient.go(AdviceClient.java:27)
at AdviceClient.main(AdviceClient.java:9)
========================
But not everyone gets it. Me, for example. But thanks to Chidu, I know for certain that this is some type of bug and not a programmer error, because Chidu sent me his entire project and I was able to run it perfectly on my machine. Yet, running the same application and class files (I even deployed his existing .ear file - I didn't recreate one using his classes) he DOES get the error. I have verified that he has done everything correctly, yet on his machine he still gets the error.
It cannot be a classpath problem, because if it were, it would fail at an earlier point.
I have a reason to suspect that this is related to a known bug in the RI, but since I am unable to reproduce the error (because it always works for me), I'm asking if someone who has this error could try the fix I'm going to give you in a moment.
Some of you HAVE been able to fix it with a terrible workaround (where you take the classes out of a package!) but we don't want you to have to do that! You could never get away with that in the real world, so we want you to keep the classes in packages.
Here's my suspicion that I would REALLY appreciate if someone could test it. Either someone who is currently getting the error, or someone who did before, and who fixed it by removing the packages (in which case, you'd have to put everything BACK into a package...)
The RI has a known bug that *might* be the problem. It has to do with the name of a method in an component interface, when it is somehow related to the interface name itself.
I think you should change the name of the method, and rebuild and redeploy the bean. If this fixes it, we will post a note on our site and O'Reilly, letting people know that they *might* have that bug.
By the way, if you run "j2ee -version" at the command-line, you'll find out which one you're using. I'm using:
Java 2 Enterprise Edition version 1.3.1, build 1.3.1-b17
And I do not get this error, even when running an application that produces this error on a different machine. I am running the Linux distribution, under Mac OSX (works under Jaguar and the new Panther), with J2SE 1.3.
So, here's the fix I want someone to try, and if it works, you will certainly be the hero.
1) Undeploy your current AdviceApp by cleaning up the server
-- stop J2EE "j2ee -stop"
-- run "cleanup" at the command-line
2) Delete your application from your projects/Advice directory (in other words, delete the .ear file), and if there are any .temp files, delete those as well.
3) Change your component interface and name the method something that does NOT have "Advice" in the name... so, instead of getAdvice(), call it getSomething()...
4) Change your bean class business method to match the business method name in the interface
5) Recompile
-- restart the server and the deploytool
6) Rebuild the bean from scratch (first build a new application, then New --> Enterprise Bean
7) Deploy the bean
8) Modify the client code to call the new method (instead of the getAdvice() method)
9) Invoke the appropriate diety / spirit / good luck charm
10) Run the client (might help to hold your breath until it's done)
Post your wonderful success story here, so I can sleep again.
So, once again, somebody who had this error PLEASE help by trying this fix. There's a good chance this is the problem.
thanks,
Kathy