Posted By:
Paul_Watson
Posted On:
Friday, February 7, 2003 03:17 AM
Can someone confirm/deny that if I obtain and utilise a datasource/connection from the ENC within a transactional CMP session bean will it become part of the beans transactional scope? I am a little confused at the moment with regards to transactions within CMP session beans. If for example I have the following method; - (void)addMessage(String message) within my session bean and it is declared transaction REQUIRED. Within the method I do this; { Context context = new InitialContext(); DataSource dbSource = (DataSource) context.lookup("java:comp/env/jdbc/EBank"); *** an enc resource variable defined Connection conn = dbSource.getConne
More>>
Can someone confirm/deny that if I obtain and utilise a datasource/connection from the ENC within a transactional CMP session bean will it become part of the beans transactional scope?
I am a little confused at the moment with regards to transactions within CMP session beans. If for example I have the following method;
- (void)addMessage(String message)
within my session bean and it is declared transaction REQUIRED. Within the method I do this;
{
Context context = new InitialContext();
DataSource dbSource = (DataSource) context.lookup("java:comp/env/jdbc/EBank"); *** an enc resource variable defined
Connection conn = dbSource.getConnection();
ps = dbConnx.prepareStatement("INSERT INTO MESSAGE VALUES(1, ?message)");
ps.executeQuery();
conn.close();
throw new RuntimeException(); *** causes transaction rollback
}
Will this be commited to the database or not? I have managed to produce test cases using our application server where dependent on from where I obtain my datasource it works or not...Is there some kind of rules on this?
thanks, Paul
<<Less