Hi Alessandro,
Alessandro Colantoni wrote:
Hi Armin.
I imagined that I wasn't doing it properly. Until now it looks going well, but I don't like it. I hope to test it properly very soon and I'll tell you. What I should do is to have 2 ojb.properties and 2 database-repository.xml. I tried to do so, putting one in the ejbs directory, and one in web-inf/classes. But daos that aren't called by ejbs too look in the files of property in ejbs.
I doubt that this will not be possible (but I'm not a expert for deployment, so I could wrong ;-)), because in one application (.ear file) you can't use different configuration files.
If your DAO outside of the beans only do read operations you will not get in trouble and it is not recommended to do persistent through session beans and through DAO bypassing the beans, in this case I have to ask why you use session beans at all?
> I know it should be just a problem of configuration, and I hope study > and solve it very soon
If you have success let me know, will be a "terrific configuration" ;-)
regards, Armin
I have this structure
Ejbs/(ojb.properties, repository.....) Ejbs/com/brujulatelecom/srv/ejb/myejb Ejbs/com/brujulatelecom/srv/dao/SalidaDAO
Then
Web/WEB-INF/classes/ com/brujulatelecom/srv/dao/SalidaDAO
Web/WEB-INF/classes/(ojb.properties, repository.....)
I want to use the same SalidaDAO in both cases. But I don't obtain /brujulatelecom/srv/dao/SalidaDAO looking in Web/WEB-INF/classes/(ojb.properties
I know it should be just a problem of configuration, and I hope study and solve it very soon
Thanks
-----Mensaje original-----
De: Armin Waibel [mailto:[EMAIL PROTECTED] Enviado el: martes, 05 de octubre de 2004 0:48
Para: OJB Users List
Asunto: Re: Ejb calling DAO
Hi,
> I would like to note one think. > Documentation says to use PersistenceBrokerFactorySyncImpl just in > managed environment. > My environment is managed (OC4J) but I use many daos normally without > ejb, and all seem go well with PersistenceBrokerFactorySyncImpl too.
A managed environment != ejb it describes an environment with services like JAAS, JNDI, JTA, ... (maybe I'm wrong ;-))
In managed environments the tx handling is done by JTA and PersistenceBrokerFactorySyncImpl interact with JTA-TxManager. You can use OJB without ejb (read operations shouldn't cause problems), but it is not allowed to use the PB-tx demarcation in managed environments. In this case you have to use JTA-UserTransaction.
The exception proves the rule. If you define an DataSource with connections which will not be automatic managed by JTA. In this case the
connections independent from JTA and behave like "normal" connections (but this couldn't be handled by PersistenceBrokerFactorySyncImpl).
regards, Armin
Alessandro Colantoni wrote:
Hi and good Monday. At the end i done it as you suggest.
I've just dune an other contructor for my dao in this way
private PersistenceBroker extBroker = null;
/**
* * @param extBroker
*/
public SalidaReservaDAO(PersistenceBroker extBroker){
this.extBroker=extBroker;
}
public SalidaReservaDAO(){
}
then in myMethod of the dao I put
try { if (extBroker!=null){ extBroker.store((SalidaReservaVO)salidaReservaVO); }else{ broker = ServiceLocator.getInstance().findBroker(); broker.beginTransaction(); broker.store((SalidaReservaVO)salidaReservaVO); broker.commitTransaction(); } } catch (ServiceLocatorException e) { broker.abortTransaction(); log.error("PersistenceBrokerException thrown in SalidaReservaDAO.store(ValueObject salidaReservaVO): " +
e.toString());
throw new DataAccessException("Error in SalidaReservaDAO.store(ValueObject salidaReservaVO): " + e.toString(),e); } finally { if (broker != null) broker.close(); }
In this way I can use Mydao in other part of the application that
don't
use ejb.
Thanks a lot for your help.
I would like to note one think. Documentation says to use PersistenceBrokerFactorySyncImpl just in managed environment. My environment is managed (OC4J) but I use many daos normally without ejb, and all seem go well with PersistenceBrokerFactorySyncImpl too.
-----Mensaje original-----
De: Alessandro Colantoni [mailto:[EMAIL PROTECTED] Enviado el: s�bado, 02 de octubre de 2004 16:25
Para: 'OJB Users List'
Asunto: RE: Ejb calling DAO
Hi.
I put
name="srvOracleDS"
location="srvOracleDS"
xa-location="srvOracleXADS" in datasource.xml
and jndi-datasource-name="srvOracleDS" in repository-database.xml
It looks like going well. Thanks very much.
When you talk about myMethod() I suppose you refer to a method of the ejb. I would like to open the broker in the Dao.
I'm trying doing something like that:
public void ejbCreate() {
}
public myEjbMethod(){
call dao1.methodh_a()
call dao2.methodh_b()
call dao3.methodh_c()
if something wrong rollback all dao operations
}
And in Daox
public method_a(){
InitialContext context = null;
try {
context = new InitialContext();
OjbPbFactory factory=
(OjbPbFactory)context.lookup("PBFactory");
}
OjbPbFactory factory=
(OjbPbFactory)context.lookup("PBFactory");
PersistenceBroker broker = factory.getInstance().....
try
{
// do work here
.....
}finally
{
if(broker != null) broker.close();
}
}
what do you think about?
-----Mensaje original-----
De: Armin Waibel [mailto:[EMAIL PROTECTED] Enviado el: s�bado, 02 de octubre de 2004 15:59
Para: OJB Users List
Asunto: Re: Ejb calling DAO
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]
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- 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]
