• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt on JNDI Reference

 
Venkatesh Rangamani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,
I see HFEJB(Pg 191 & 196) and the spec stating that We cant access database in the beans constructor or ejbCreate or setSessionContext for a SessionBean. I tried doing a lookup as:


Connection con = null;
Context ctx = null;
try {
ctx = new InitialContext();
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/scott");
con = ds.getConnection();
con.prepareStatement("Select 1 from dual").execute();
con.close();
} catch (Exception ne) {
ne.printStackTrace();
}


Above code works fine no Exception is thrown. I am using Weblogic 8.1. Is weblogic deviating from the spec?

I just noted something else in spec:
"For example, it would be wrong to perform database operations within a session bean�s ejbCreate or ejbRemove method and to assume that the operations are part of the client�s transaction.". So it is not about accessing but about wether the operation is in transaction or not! Am i rite?

Thanks
Venkat
[ May 28, 2007: Message edited by: Venkatesh Rangamani ]
 
Mansur Khan
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Weblogic may allow the behaviour. These digressions are vendor-specific. Onemore thing which comes to mind about weblogic-specific behaviour is that PortableObject.narrow() is not mandatory with remote lookups.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, i think "being a part of the transaction" does matter!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic