views:

25

answers:

1

I have existing project which uses 2 database (DB2),and the records which are saved in the 2 databases are related.So the transactions need to be maintained.Eg whenever a new thing is to be added then entries must be done to x number of tables in Database1 and and y number of tables in database2. Now in the code that is preexisting(developed by somone else) i see some thing like

UserTransaction utx = getTranscationU();  
//getTranscation() is a user defined method as show   below

public UserTransaction getTransactionU()  {
        InitialContext ic = new InitialContext();
        return (UserTransaction) ic.lookup("java:comp/XYZ");
    }

so in code following sequence is followed: 1)start utx 2)create a seperate entity manager ems for db1 and db2 3)create entries in both tables using this ems 4)if any exception is thrown then rollback utx

Now my question is

  1. 1)will this code make sure that entries are entered in both db or none of them?
  2. 2)Can any one explain me what does code inside getTransactionU() does?
  3. 3)where is XYZ defined?
+1  A: 
  1. When the UserTransaction is initialized, if both entity managers are using Datasources linked to the transaction manager, all its operations will be included at the transaction. The transaction must be a XATransaction (distributed) if you are accessing different databases.
  2. The getTransactionU() method is accesing the JEE container's Naming Directory through JNDI, where the Transaction manager has to be configured.
  3. It's the path of the transaction manager set up on your server.
Tomas Narros
thanks: user tranacation is initialised as utx = getTranscationU().Can you please tell me the file where i shold look for XYZ, i mean point no 3 and 2
akp
It depends on the JEE container your code is runnig at. The container configuration file it's not a JEE standard (JBoss uses a set of files, with Websphere you better look for it through its Admin Console, etc)
Tomas Narros