Hi all.
I have a transaction on my ejb method that call various DAOs.
DAOs access dB through OJB
I'm working with OC4J.
I've done a start up class similar to that in the documentation adapted
to OC4J
 
 
package com.brujulatelecom.srv.startup;
import com.evermind.server.OC4JStartup;
import java.io.Serializable;
import javax.naming.*;
import java.util.*;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory;
import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
 
 
 
/** 
 * This is an example of a Startup class which can be registered with 
 * OC4J and which will be instantiated and called when the container 
 * is started.
 * 
 * Implements the <code>com.evermind.server.OC4JStartup</code>
interface.
 */
public class OjbPbStartup implements OC4JStartup,OjbPbFactory,
Serializable{
    private String defaultPropsFile =
"../srv/aplicacion/ejbs/OJB.properties";
    
    public PersistenceBrokerFactoryIF getInstance(){
        return PersistenceBrokerFactoryFactory.instance();
    }
    
    
 
  
    /**
     * This method is called before any applications have been deployed
     *
     * @param args - contains the parameters that have been specified
for
     * this operation in the OC4J configuration file.
     * @param context - the JNDI context for the server.
     * @return An arbitrary string value
     */
    public String preDeploy(Hashtable args, Context context) throws
Exception {
        return "";
    }
    private void bind(Context ctx, String name, Object val) throws
NamingException{
        Name n;
        for(n = ctx.getNameParser("").parse(name); n.size() > 1; n =
n.getSuffix(1)){
            String ctxName = n.get(0);
            try{
                ctx = (Context) ctx.lookup(ctxName);
            }
            catch(NameNotFoundException namenotfoundexception){
                ctx = ctx.createSubcontext(ctxName);
            }
        }
        ctx.bind(n.get(0), val);
    }
 
  
    /**
     * This method is called after any applications have been deployed.
     *
     * @param args - contains the parameters that have been specified
for
     * this operation in the OC4J configuration file.
     * @param context - the JNDI context for the server.
     * @return An arbitrary string value
     */
    public String postDeploy(Hashtable args, Context context) throws
Exception {
        try{
            String jndiName = (String) args.get("jndiname");
            if(jndiName == null || jndiName.length() == 0)
                jndiName = OjbPbFactory.DEFAULT_JNDI_NAME;
 
            String propsFile = (String) args.get("propsfile");
            if(propsFile == null || propsFile.length() == 0)
            {
                System.setProperty("OJB.properties", defaultPropsFile);
            }
            else
            {
                System.setProperty("OJB.properties", propsFile);
            }
    
            //InitialContext ctx = new InitialContext();
            bind(context, jndiName, this);
    
            // return a message for logging
            return "Bound OJB PersistenceBrokerFactoryIF to " +
jndiName;
        }
        catch(Exception e){
            e.printStackTrace();
            // return a message for logging
            return "Startup Class error: impossible to bind OJB PB
factory";
        }
        //System.out.println(getClass().getName() + " postDeploy method
called");    
        //return null;
        
    }
    
}
 
 
package com.brujulatelecom.srv.startup;
 
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.core.PersistenceBrokerFactoryIF;
 
public interface OjbPbFactory{
    public static String DEFAULT_JNDI_NAME = "PBFactory";
    public PersistenceBrokerFactoryIF getInstance();
}
 
 
If  I do :
 
OjbPbFactory ojbFactory= (OjbPbFactory)context.lookup("PBFactory");
PersistenceBroker broker =
ojbFactory.getInstance().defaultPersistenceBroker();
 
In the ejbCreate() I don't have problems.
But If I put it in the Dao called by ejb I get the following error:
04/10/02 14:11:42
[org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl] ERROR:
Unexpected exception when start i
ntern pb-tx
04/10/02 14:11:42 null
04/10/02 14:11:42 java.lang.ClassCastException
04/10/02 14:11:42       at
org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newConne
ctionFromDataSource(C
onnectionFactoryAbstractImpl.java:195)
04/10/02 14:11:42       at
org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.lookupCo
nnection(ConnectionFa
ctoryAbstractImpl.java:112)
04/10/02 14:11:42       at
org.apache.ojb.broker.accesslayer.ConnectionFactoryManagedImpl.lookupCon
nection(ConnectionFac
toryManagedImpl.java:33)
04/10/02 14:11:42       at
org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.getConnection(Co
nnectionManagerImpl.j
ava:105)
04/10/02 14:11:42       at
org.apache.ojb.broker.accesslayer.ConnectionManagerImpl.localBegin(Conne
ctionManagerImpl.java
:147)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerImpl.beginTransaction(Persis
tenceBrokerImpl.java:
394)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.DelegatingPersistenceBroker.beginTransaction(
DelegatingPersistence
Broker.java:138)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl$PersistenceB
rokerSyncImpl.internB
egin(PersistenceBrokerFactorySyncImpl.java:280)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl$PersistenceB
rokerSyncImpl.access$
000(PersistenceBrokerFactorySyncImpl.java:225)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl.wrapRequeste
dBrokerInstance(Persi
stenceBrokerFactorySyncImpl.java:153)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactoryDefaultImpl.createPer
sistenceBroker(Persis
tenceBrokerFactoryDefaultImpl.java:105)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl.createPersis
tenceBroker(Persisten
ceBrokerFactorySyncImpl.java:116)
04/10/02 14:11:42       at
org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersi
stenceBroker(Persiste
nceBrokerFactoryBaseImpl.java:158)
 
and the error on my code is on the line PersistenceBroker broker =
ojbFactory.getInstance().defaultPersistenceBroker();
I yet got sure that the problem is in  . defaultPersistenceBroker() and
not in .getIstance.
In other word I get the PersistenceBrokerFactoryIF rightly, but I fail
when trying to get the PersistenceBroker
 
 
 Can AnyOne help me?
What I wnt to do is to have a rollback on all Dao if anyone fails.
Thanks in advance.

Reply via email to