Code on entity bean being looked up from a session bean and transactionrollback

2001-07-15 Thread aby

Hi everyone,

I have a problem with a sequence like this

Stateless session bean (bit of sql in a function f1) and calls an
entity bean. When the entity bean fails the changes done by sql are
not rolled back. (But if sql fails the entity bean changes are rolled
back).

So I tried another method suggested i.e. the sql was replcaed by
entity bean entity1 which was going to call entity22.

Suppose entity1 calls entity2 and entity2 fails, then there
is a rollback(for both), but when I shut down the server all the
changes which
were supposed to be rolled back are undone!

And another case when something in entity1 fails, the entity2 changes
are not rolled back and it looks like I am still back to square one.

Any idea if this is an orion bug or something? i would really love to
get down to the root of this problem. If I start writing sql code in
my session beans instead of using entity beans. Everything works out
perfectly well. But I still think that this is not a solution.

I still feel that even if I have my sql in the method of one
statelesss session bean and one entity update all should be able to
work. After all, the same code works in J2EE. I might probably be
missing something.

Hs anyone got a simple example on having a mix of sql and entity
updates in one method of a statelss(or stateful) bean which can do a
rollback it the entity fails.

Thanks in advance.

Kind Regards
Aby






Re: Transaction problems

2001-07-13 Thread aby


Hi Christian,
Frankly we have the same problem, trying to access the entity bean
through a session bean and not being able to rollback. However
rollback is working perfectly fine in stateful/stateless session bean.

One thing which I noticed in your xml file is that you have not given
the tranas-attribute 'Required'. You have to do that in order to get
at least the stateless or stateful beans to work on transactions. E.g.
do two sql 'inserts' in one session bean in one method and if one
fails throw EJBException and the rollback happens.

But in the case of an entity bean being accessed by a session bean, if
the entity throws an EJBException in the ejbStore() that is not being
caught by the session bean and so the rollback does not occur.

If you want the code for the session beans working with rollback, I
can send it to you. I have to thank Mr Rob Lapenese for that bit of
help.

Kind Regards
Aby Philip





Exception thrown in Entity bean not being caught by the session bean(butworks in J2EE RI)

2001-07-13 Thread aby

Hi everyone,

Basically what I am trying to do is I have a function in a session
bean called setDBItems(String, String, String, String). This function
is supposed to do (in sequence)

1) sql insert to a table 'sabra' with the first two parameters of the
function.
2) an entity bean update using the 'account.credit(100.00)' function.
It updates the table accountums.
3) another sql insert to the table 'sabra' using the last two
parameters of the function.

My aim is to have one of these steps fail so that all the 3 database
inserts/updates rollback. e.g. if the step 3 fails, step 1 and 3
should rollback. This is working in Orion. That is the insert is done
by a normal PreparedStatement and not by and entity bean.

The next aim is to have the entity bean 'update' fail so that the
other normal 'sqls' rollback. The balance field in the accountums
table has a length of NUMBER(5,2) so when I call the entity bean's
credit (account.credit(12345.00)) the entity update should fail, which
should rollback all the other sqls.

Since this is a transaction on the setDBItems() the ejbStore() is only
called towards the end of the setDBItems() i.e. step 1) and step 2)
and step 3) happen, but only at the end of the transaction of the
setDBItems () the ejbStore() of the entity is being called. This is
fine and this is how it should work. The ejbStore() throws an
EJBException, but this is not being caught in the setDBItems(). If
this happened, then the setDBItems would be able to throw an
EJBException which would rollback everything and I would be a happy
man.

Now the main thing is that the Exception thrown by the store does not
come to the Session bean. I tried using the UserTransaction so that
when I say ut.commit(), the ejbStore() would be called and I could
catch the Exception thrown by the entity bean, but still in this case
the Exception is not being caught by the Session bean although the
code is there. I tried throwing a RemoteException with same results.

We are using Oracle.
Using the thin driver. (jdbc:oracle:thin:@192.168.0.5:1521:dcom)

This same program works well in J2EE. I had a previous problem with
transactions in Orion sometime back and found out that it was because
the Remote was throwing Exception instead of any other. When I changed
it to some RemoteException, it worked. So I am beginning to wonder if
Orion has a different way of implementing things. but anyway I guess
you would be able to see better reason on this.

If anyone has a working example of what I am trying to do (in Orion),
I would appreciate it if someone could send the same thing to me.

Thanks very much.

Thanks
Kind Regards
Aby Philip






RE: How can I get UserTransaction or TransactionManager

2001-07-08 Thread aby


Hi HK,
I am getting puzzled now on this.
Maybe you could try UserTransaction ut = context.getUserTransaction();

where 'context' is the SessionContext or EntityContext variable which
is declared at the top of the EJB as a variable.

Kind Regards
Aby





Re: How can I get UserTransaction or TransactionManager

2001-07-07 Thread aby


Hi HK,
I think you should try

java:comp/env/UserTransaction

Regards
Aby




HyungKee Hwang [EMAIL PROTECTED]@orionserver.com on 07-07-2001
09:10:55 AM

Please respond to Orion-Interest [EMAIL PROTECTED]

Sent by:  [EMAIL PROTECTED]


To:   Orion-Interest [EMAIL PROTECTED]
cc:
Subject:  How can I get UserTransaction or TransactionManager


Hello, all.

Can you give me some advice how to get UserTransaction or
TrasactionManger?

I wrote some codes in my application as follows;

 // Below codes are from Orion FAQ
import javax.naming.*;
import javax.transaction.*;
...
TransactionManager manager = (TransactionManager)new InitialContext
().lookup(java:comp/UserTransaction);
I didn't have any problem compiling my codes, but I met below error
while running my application
avax.naming.NameNotFoundException: java:comp/UserTransaction not found
at com.evermind.server.rmi.RMIContext.lookup(JAX)
Thank you in advance.
-HK








Transaction management in BMP through Session bean

2001-07-06 Thread aby

In a BMP, if we throw an EJBException all the changes would be rolled
back by the container, right? Or do we have to write code to do that?

I was reading through your reply in the list  and I have a doubt
regarding something regarding transaction handling in BMP entity
beans. I am using the entity bean in a session bean and have two sql
statements and one entity update. If one of the sql statements fails
and the entity is updated , the changes are all rolled back, but in
the case of the entity failure to update, the sql statement changes
are not rolled back and I get an error saying

System/communication error: Transaction was rolled back: Error preparing bean in
stance: com.evermind.transaction.MarshallingXAException; nested exception is:
com.evermind.transaction.MarshallingXAException

The entity bean is throwing an EJBException back to the Session bean, but the session 
bean does not catch
it and continues forward as if nothing happened.

The funny thing is that the queries are placed like this

sqlinsert 1...
entitybean update
sqlinsert 2.

So the flow becomes

sqlinsert 1 happens then sqlinsert 2 and only in the end does the entity bean throw 
the exception

any idea why this happens?

Can anyone help me on this. The BMP entity has persistence

persistence-typeBean/persistence-type

Thanks
Kind Regards
Aby





Exception thrown by BMP not being caught by Session

2001-07-06 Thread aby

Hello everyone,
I have an entity bean(Account)  which is throwing an exception and
this is not being caught by the session bean. The sequence is that

one insert
entity update
another insert.

all should go as one unit of transaction or not at all.

We try to update the entity bean with an illegal value so that it
fails and the whole transaction rolls back.

The code is as below

PreparedStatement prepFirst = con.prepareStatement(insert into sabra values(?,?));
prepFirst.setString(1,id);
prepFirst.setString(2,name);
prepFirst.executeUpdate();
prepFirst.close();
try
{
 InitialContext context = new InitialContext();
 Object objref = context.lookup(java:comp/env/ejb/AccountService);
 AccountHome home =
   (AccountHome)PortableRemoteObject.narrow(objref,
  AccountHome.class);
 Account account = home.findByPrimaryKey(123);
 account.credit(12345.00);
 System.out.println(here after credit);

 System.out.println(here again);
 PreparedStatement prepTwo = con.prepareStatement(insert into sabra values(?,?));
 prepTwo.setString(1,idFail);
 prepTwo.setString(2,nameFail);

 prepTwo.executeUpdate();

 System.out.println(here again again);
 prepTwo.close();
 con.close();
 }
 catch(Exception e)
 {
  System.out.println(here babe exception);
  throw new EJBException(failed babe);
 }

The sequence in which actions happen

the sql insert one happens
the entity does not throw an exception yet
the sql insert two happens

and then
the ejbstore of the entity is called which only then has the error happening and the
EJBException is thrown, but there is nothing to catch it then.

o/p is like this

here after credit
here again
here again again

and then the exception thrown by the entity although this should have happened before 
'here after credit'

although the sequence should have been

only the exception thrown by the entity bean and then nothing else.

Can anyone help out?

Kind Regards
Aby Philip






Re: Exception thrown by BMP not being caught by Session

2001-07-06 Thread aby


Hi Jeff,

Thanks very much for the reply. I am not using the resource-ref thing
but I tried using the xa-location and the ejb-location (two different
programs), in both the cases the output is as you say it is. But the
problem I have now is that in my code, it's only by the time the whole
transaction ends that I have knowledge that the entity bean fails and
then I cannot throw the EJBException so that the container rollback
all the sql inserts.

Any way around this problem? Can I know whether the entity bean failed
as soon as the entityBean.setCredit(100.00) is called? Or can I know
of it somewhere in the function?

Now since the ejbStore is called only at the end of the transaction,
should I start to use the UserTransaction in the session bean, so that
when I commit the trans...I know if the entity has failed? Is it a
must that I should use the resource ref?

I have the same output in the J2EE RI (ejbStore) called after the
transaction, but in that case the container rolls back all the
transactions, but in orion it goes this way.

Thanks very much for the help you are giving me. I am in a tight
situation here.

Thanks
Kind Regards
Aby





Transaction problem in EJB

2001-06-21 Thread aby

Hi everyone,

I have a problem with transactions.

My aim is to have two sql 'inserts' in one function. The function is
covered by the 'Required' attribute in the xml file. The data source
is used from the 'ejb-location'. If one insert fails , the container
rolls back all the other database inserts in the function. But the
example working in the J2EE implementation is not working in the Orion
one. Do I have to go for a 'resource ref' in the xml file, is it
because of this the transaction fails? Because in all the examples
everyone accesses the data sources using the jdbc/X which is there
in the data sources.xml directly.

the code is shown below.

data-source
  class=com.evermind.sql.DriverManagerDataSource
  name=OracleDS
  location=jdbc/OracleCoreDS
  xa-location=jdbc/xa/OracleXADS
  ejb-location=jdbc/OracleDS
  connection-driver=oracle.jdbc.driver.OracleDriver
  username=scott
  password=tiger
  url=jdbc:oracle:thin:@192.168.0.5:1521:dcom
  inactivity-timeout=30
 /

The code in the bean (Session)

InitialContext ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup(jdbc/OracleCoreDS);
Connection con = ds.getConnection();

I have two updates in one function (setDBItems()). I have put a 'Required' attribute 
for it in the ejb-jar.xml

container-transaction
  descriptionno description/description
  method
 ejb-nameMyCart/ejb-name
 method-name*/method-name
  /method
  trans-attributeNotSupported/trans-attribute
   /container-transaction
   container-transaction
  method
 ejb-nameMyCart/ejb-name
 method-namesetDBItems/method-name
 method-params
method-paramjava.lang.String/method-param
method-paramjava.lang.String/method-param
method-paramjava.lang.String/method-param
method-paramjava.lang.String/method-param
 /method-params
  /method
  trans-attributeRequired/trans-attribute
  /container-transaction

The problem here is that the first update occurs but when the second fails the first 
does not rollback.
As per my understanding any problem in one of the database transactions in the 
function rolls back al the others
in the same function.

Any clue on this? If someone has some example code on this, could you please send it 
to me?

Thanks in advance
Regards
Aby Philip





Transaction and DriverManagerXADataSource

2001-06-19 Thread aby

Hello everyone,
I am new to orion server and am trying to find out how to use
transaction handling within orion. Now within the datasource.xml file.
I have got something like this

data-source
  class=com.evermind.sql.DriverManagerDataSource
  name=OracleDS
  location=jdbc/OracleCoreDS
  source-location = c:\orion\j2ee\home\orion.jar
  xa-location=jdbc/xa/OracleXADS
  ejb-location=jdbc/OracleDS
  connection-driver=oracle.jdbc.driver.OracleDriver
  username=scott
  password=tiger
  url=jdbc:oracle:thin:@192.168.0.5:1521:dcom
  inactivity-timeout=30
 /

In this case when I am using the code in the client as

InitialContext ic = new InitialContext();
DataSource ds = (DataSource)ic.lookup(jdbc/OracleDS);
Connection con = ds.getConnection();

then the pooled connection happens. As I understand there is a place where the 
transactions can be rolled back if an
'EJBException' is thrown by the container. Now the doubt is that this does not happen 
with the OracleDS.

So I thought that I should use the

class=com.evermind.sql.DriverManagerXADataSource in the xml file

and in the client code use

DataSource ds = (DataSource)ic.lookup(jdbc/xa/OracleXADS);

The problem is that the server does not start saying that it needs the 
source-location. can anyone
help me out on this? Thanks

i would also like to know how to say 'transaction' required for one of the function of 
my EJB in orion.
I could do this in the J2EE RI using the deploytool, but I am totally lost here.

Thanks in advance

Regards
Aby