Hi again,
I would advice to use 'jdbc/srvOracleCoreDS' as jndi-datasource-name in OJB - long shot ;-)
Does this cause same error?
[off-topic]
Further on in ejbCreate() in your bean I would only lookup the OjbPbFactory instance and keep it as inst var in bean. Then on each method call lookup a PB instance, do your work and close the instance at end of method.
private OjbPbFactory factory;
public void ejbCreate() {
InitialContext context = null;
try {
context = new InitialContext();
OjbPbFactory factory=
(OjbPbFactory)context.lookup("PBFactory");
}public void myMethod()
{
// or use a helper method in base bean class to get PB
PersistenceBroker broker = factory.getInstance().....
try
{
// do work here
.....
}finally
{
if(broker != null) broker.close();
}
}
....regards, Armin
Alessandro Colantoni wrote:
Hi Armin This is my ejbCreate()
public void ejbCreate() {
InitialContext context = null;
try {
context = new InitialContext();
OjbPbFactory ojbFactory=
(OjbPbFactory)context.lookup("PBFactory");
PersistenceBroker broker =
ojbFactory.getInstance().defaultPersistenceBroker();
}catch(NamingException e){
//throw new ServletException("Error looking Data Source", e);
}
}
Here everythink goes well, but I need this lines in the Dao and not here
The object returned by the lookup in an istance of OjbPBStartup.
Then I do ojbFactory.getInstance() and I get an instance of
PersistenceBrokerFactorySyncImpl in the dao too.
The problem is that in the Dao when I call
pbf.defaultPersistenceBroker(), where pbf is the istance of
PersistenceBrokerFactorySyncImpl, I got the error.
The mistery is why it work correctly in ejbCreate and not in the Dao.
I read yet the lines you told, and I thought that the problem coud be in
the datasource definition:
I send it to you if you can have a look ;-)
<data-source
class="com.evermind.sql.DriverManagerDataSource"
name="srvOracleDS"
location="jdbc/srvOracleCoreDS"
xa-location="jdbc/xa/srvOracleXADS"
ejb-location="jdbc/srvOracleDS"
connection-driver="oracle.jdbc.driver.OracleDriver"
username="srv_des"
password="srv_des"
url="jdbc:oracle:thin:@192.168.80.212:1521:ORA92"
inactivity-timeout="30"
/>
I'm not very esperienced with this and I copied it from an example. I don't Know exactly what do location, xa-location, and ejb-location. My repository-database.xml is
<jdbc-connection-descriptor jcd-alias="default" default-connection="true" platform="Oracle" jdbc-level="2.0" jndi-datasource-name="jdbc/xa/srvOracleXADS" protocol="jdbc" username="srv_des" password="srv_des" eager-release="false" batch-mode="false" useAutoCommit="0" ignoreAutoCommitExceptions="false">
Have I done all right (well, no, of course)
Thank for the help
-----Mensaje original-----
De: Armin Waibel [mailto:[EMAIL PROTECTED] Enviado el: s�bado, 02 de octubre de 2004 15:00
Para: OJB Users List
Asunto: Re: Ejb calling DAO
Hi Alessandro,
the code causing the CCE is
> 04/10/02 14:11:42 at > org.apache.ojb.broker.accesslayer.ConnectionFactoryAbstractImpl.newConne > ctionFromDataSource(C > onnectionFactoryAbstractImpl.java:195)
in this method OJB does: <snip> InitialContext ic = new InitialContext(); ds = (DataSource) ic.lookup(jcd.getDatasourceName()); <===!!! </snip>
So it seems that the object returned by the lookup is not instance of DataSource or it's a side-effect of another problem.
Could you describe your test more detailed? You lookup OjbPbFactory in ejbCreate method? And the DAO use an session bean or does directly access OJB via JNDI lookup?
regards, Armin
Alessandro Colantoni wrote:
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.
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
