Hi Dino,

I'm working on this, the patch has some unexpected side-effects in managed environments ;-)
Hope to find a solution till tomorrow.


regards,
Armin

Dino Di Cola wrote:
Dear Armin,

I am testing your patch on
ImplementationJTAImpl#registerOpenDatabase.
The problems regarding the ejbCreate() method
disappeared. Unfortunately I got some problems with
the org.odmg.Database#deletePersistent now.
Again this problem is related to Transaction
Management and was not present with the previous
Oracle9iAS 9.0.2.2 version.


The test case I present here is again a simple J2EE
application made up of a test stateless session bean
with a single business method invoked via RMI.
The configuration is the same of the previous e-mail.
What I am trying to do is basically to lookup for an
object (es. SentMail) and deleting it with the
Database#deletePersistent method:

/* this is done in ejbCreate()... */
org.odmg.Implementation odmg = OJB.getInstance();
org.odmg.Database db = odmg.newDatabase();
db.open(DEF_DATABASE_NAME,
Database.OPEN_READ_WRITE); [...]


        /* this is done in the business method... */
        SentMail objSentMail = (SentMail)
lookupObject(SentMail.class, 4);
        db.deletePersistent(objSentMail);

The object is actually found on the DB but when I try
to delete it I got the following exception:

[exec] The following exception has been catched:
Transaction was rolled back:
org.odmg.TransactionNotInProgressException: No
transaction in progress, cannot delete persistent;
nested exception is:
[exec]
com.evermind.server.rmi.OrionRemoteException:
Transaction was rolled back:
org.odmg.TransactionNotInProgressException: No
transaction in progress, cannot delete persistent
[exec]
org.odmg.TransactionNotInProgressException: No
transaction in progress, cannot delete persistent
[exec] at
OJB_Tx_StatelessSessionBeanWrapper76.test(OJB_Tx_StatelessSessionBeanWrapper76.java:164)
[exec] at
java.lang.reflect.Method.invoke(Native Method)
[exec] at
com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:119)
[exec] at
com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
[exec] at
EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:804)
[exec] at
java.lang.Thread.run(Thread.java:479)
[exec] at connection to c-01-091/10.2.20.20
as admin
[exec] at
com.evermind.server.rmi.RMIConnection.EXCEPTION_ORIGINATES_FROM_THE_REMOTE_SERVER(RMIConnection.java:1576)
[exec] at
com.evermind.server.rmi.RMIConnection.invokeMethod(RMIConnection.java:1529)
[exec] at
com.evermind.server.rmi.RemoteInvocationHandler.invoke(RemoteInvocationHandler.java:55)
[exec] at
com.evermind.server.rmi.RecoverableRemoteInvocationHandler.invoke(RecoverableRemoteInvocationHandler.java:22)
[exec] at
com.evermind.server.ejb.StatelessSessionRemoteInvocationHandler.invoke(StatelessSessionRemoteInvocationHandler.java:50)
[exec] at __Proxy5.test(Unknown Source)
[exec] at
it.enidata.psv.test.ejb.client.TestOJB_Tx.main(TestOJB_Tx.java:45)
[exec]
[exec] Nested exception is:
[exec] org.odmg.TransactionNotInProgressException: No
transaction in progress, cannot delete persistent
[exec] at
org.apache.ojb.odmg.DatabaseImpl.deletePersistent(Unknown
Source)
[exec] at
it.enidata.psv.test.ejb.OJB_TxBean.test(OJB_TxBean.java:144)
[exec] at
OJB_Tx_StatelessSessionBeanWrapper76.test(OJB_Tx_StatelessSessionBeanWrapper76.java:115)
[exec] at
java.lang.reflect.Method.invoke(Native Method)
[exec] at
com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:119)
[exec] at
com.evermind.server.rmi.RMICallHandler.run(RMICallHandler.java:48)
[exec] at
EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:804)
[exec] at
java.lang.Thread.run(Thread.java:479)
[exec] at connection to
c-01-091.prirm.pride.it/10.2.20.20
[exec] at
com.evermind.server.rmi.OrionRemoteException.receive(OrionRemoteException.java:130)
[exec] at
com.evermind.server.rmi.RMIConnection.handleMethodInvocationResponse(RMIConnection.java:1691)
[exec] at
com.evermind.server.rmi.RMIConnection.run(RMIConnection.java:532)
[exec] at
com.evermind.server.rmi.RMIConnection.run(RMIConnection.java:275)
[exec] at
EDU.oswego.cs.dl.util.concurrent.PooledExecutor$Worker.run(PooledExecutor.java:798)
[exec] at
java.lang.Thread.run(Thread.java:484)


You can find the complete source code for the
OJB_TxBean here below.


I am again in your hands... ;) Thanks in advance.

Regards,


Dino.


ps. (from previous thread...)

3. I commented out the beginInternTransaction()
invocation. Clearly this method is equally invoked
following another code flow. Does it mean it was

called twice before your patch?

this could be the case, but it doesn't matter,

because


beginInternTransaction() take care of this.

nearly all operations of the odmg-api have to be in

context of a


transaction and in managed environments it's not

allowed to do OJB/ODMG


related transaction demarcation, thus you always have

to use JTA


transactions and the easiest way is to use

container-managed tx.

Alternative you can use bm-tx via UserTransaction.

--
***********************************************************************
**** Source code for the session bean
*********************************
***********************************************************************
public class OJB_TxBean implements SessionBean {

private SessionContext sessionContext;
private static final String DEF_DATABASE_NAME =
"dsOJB";
private Implementation odmg;
private Database db;
public OJB_TxBean() {}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void ejbCreate() throws CreateException {
try {
init();
} catch (InitException e) {
throw new CreateException(e.getMessage());
}
}


private void init() throws InitException{
/* ---------------------------- */
/* Step0 - Getting log4j logger */
/* ---------------------------- */
Logger logger =
Logger.getLogger("psv.j2ee.testing");
logger.debug("OJB_TxBean - init(): begin");
odmg = null;
db = null;
/* ------------------------------------ */
/* Step1 - Initializing ODMG connection */
/* ------------------------------------ */
logger.debug("OJB_TxBean - init(): initializing
ODMG connection [BEGIN]");
odmg = OJB.getInstance();


logger.debug("OJB_TxBean - init():
odmg.newDatabase()");
db = odmg.newDatabase();
try {
logger.debug("OJB_TxBean - init(): open new
database " + db + " using databaseName name " +
DEF_DATABASE_NAME);
db.open(DEF_DATABASE_NAME,
Database.OPEN_READ_WRITE); } catch (ODMGException e) {
logger.error("OJB_TxBean - init(): Database open
failed", e);
throw new InitException(e.getMessage());
} logger.debug("OJB_TxBean - init(): initializing
ODMG connection [END]"); }
public void ejbRemove() {
Logger logger =
Logger.getLogger("psv.j2ee.testing");
logger.debug("OJB_TxBean - ejbRemove(): closing
ODMG connection [BEGIN]");
try {
logger.debug("OJB_TxBean - ejbRemove():
db.close(): " + db);
if (db != null) db.close();
} catch (ODMGException e) {
logger.error("OJB_TxBean - ejbRemove(): closing of
database failed", e);
}
db = null;
odmg = null;
logger.debug("OJB_TxBean - ejbRemove(): closing
ODMG connection [END]"); }
public void setSessionContext(SessionContext
sessionContext) {
this.sessionContext = sessionContext;
}
protected PObject lookupObject(Class target, long
oid) {
Logger logger =
Logger.getLogger("psv.j2ee.testing"); logger.debug("OJB_TxBean - lookupObject(): begin");

PersistenceBroker broker = null;
PObject pObject = null;


        try {
                broker =
PersistenceBrokerFactory.defaultPersistenceBroker();

                Criteria crit = new Criteria();
                crit.addEqualTo("oid", new Long(oid));
                Query query = new QueryByCriteria(target, crit);

                java.util.Iterator iter =
broker.getCollectionByQuery(query).iterator();

if (iter.hasNext()) pObject = (PObject)
iter.next();
} catch (Exception e) {
logger.error("OJB_TxBean - lookupObject(): Query
failed", e);
throw new EJBException("OJB_TxBean - lookupObject(): Query failed", e);
} finally {
if (broker != null)
broker.close();
}

logger.debug("OJB_TxBean - lookupObject(): end");
return pObject;
}
public String test() throws java.rmi.RemoteException
{
Logger logger =
Logger.getLogger("psv.j2ee.testing"); logger.debug("OJB_TxBean - test(): begin");

/* ---------------------- */
/* --- Business Stuff --- */
/* ---------------------- */
logger.debug("OJB_TxBean - test(): odmg : " +
odmg);
SentMail objSentMail = (SentMail)
lookupObject(SentMail.class, 4);
logger.debug("OJB_TxBean - test(): objSentMail : "
+ objSentMail);
logger.debug("OJB_TxBean - test():
objSentMail.getSubject() : " +
objSentMail.getSubject());
logger.debug("OJB_TxBean - test():
objSentMail.getSend_to() : " +
objSentMail.getSend_to());
logger.debug("OJB_TxBean - test():
objSentMail.getRecipient() : " +
objSentMail.getRecipient());

logger.debug("OJB_TxBean - test(): objSentMail : "
+ objSentMail);
db.deletePersistent(objSentMail);

logger.debug("OJB_TxBean - test(): end");
SimpleDateFormat simpleDateFormat = new
SimpleDateFormat("dd.MM.yyyy hh:mm:ss");
return "OJB_TxBean - test(): done [" + simpleDateFormat.format(Calendar.getInstance().getTime())
+ "]";
}
}
--






--- Armin Waibel <[EMAIL PROTECTED]> ha scritto:

Hi Dino,

Dino Di Cola wrote:


Dear Armin,
first of all thanks for your prompt reply!

I applied the change to the
ImplementationJTAImpl#registerOpenDatabase and
executed the test from scratch. My simple test application works fine now.
I deployed also the main J2EE application and

works

also there at first sight.

I would like to have more insight from you

regarding

the patch you proposed to apply in
ImplementationJTAImpl class.

1. You wrote the following: "OJB always lookup a
running JTA-transaction this can't be successful

when

db.open(...) is called on ejbCreate()".
  Could you please give me more info? I cannot

see

the problem with ejbCreate(). Thanks!


ejbCreate() was called on session bean
initialization, this could be done e.g. at startup of your appServer to setup a
pool of session bean instances. Thus there is no guarantee that the
session bean was created in context of a running tx.




2. You wrote me it could be a "bug" in odmg
implementation. And clearly you seems right.

I will fix this in CVS ASAP.



I cannot understand however why it was

successfully

running on previous versions of ora9ias!?!


e.g. in your previous version your appServer doesn't
setup a session bean pool at startup, so the instances were created
when needed and thus when a tx was reachable --> no exception




3. I commented out the beginInternTransaction()
invocation. Clearly this method is equally invoked
following another code flow. Does it mean it was called twice before your

patch?

this could be the case, but it doesn't matter,
because beginInternTransaction() take care of this.




4. My Session Bean is substantially very close to


src\ejb\org\apache\ojb\ejb\odmg\ODMGSessionBean.java

(taken from the db-ojb-1.0.rc7 distribution).
  The only difference I note is on the "Required"
attribute marked in the ODMGSessionBean.java

javadoc.

I use "NotSupported" instead. Have I to change the attribute to "Required"?



nearly all operations of the odmg-api have to be in
context of an transaction and in managed environments it's not
allowed to do OJB/ODMG related transaction demarcation, thus you always
have to use JTA transactions and the easiest way is to use
container-managed tx.
Alternative you can use bm-tx via UserTransaction.
I wonder how you could use odmg-api in managed
environment with transaction attribute "NotSupported"?




5. I am quite sure about this bug (anyway I will

check

it more and more and I will keep you informed). If you are certain of this bug too, in what

release

do you think to fix it?

Think the next upcoming OJB 1.0.1 will contain this fix.



Have you planned a target release date for next

OJB

release?

We planed a maintenance release 1.0.1 for last week ;-) I'm sure we will release the new version in near future.



What can I do in the meantime a new release

will be

officially distributed?


use the patched class



Armin, I really appreciated your help.
Hope you will answer to all my questions without
getting bored :)


In return for services, never run down OJB ;-)

regards,
Armin



Thanks,

d.
--





        
                


____________________________________________________________

Yahoo! Companion - Scarica gratis la toolbar di

Ricerca di Yahoo!


http://companion.yahoo.it



---------------------------------------------------------------------

To unsubscribe, e-mail:

[EMAIL PROTECTED]

For additional commands, e-mail:

[EMAIL PROTECTED]




---------------------------------------------------------------------

To unsubscribe, e-mail:
[EMAIL PROTECTED]
For additional commands, e-mail:
[EMAIL PROTECTED]








____________________________________________________________
Yahoo! Companion - Scarica gratis la toolbar di Ricerca di Yahoo! http://companion.yahoo.it


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to