Summary:
It seems as though my two bean operations are executing under different DB
connections even though they are encapsulated in a TransactionManager
transaction block
(and please don't tell me that I have to write a session bean ... there are
many reasons why this is impractical for my particular application ... :-)
... )
Detail:
I have a servlet (running in EmbeddedTomcat) which does the following: It
looks up an existing record from the credit_card table, changes the
billing_address_id to some other billing address, then attempts to remove
the old address record from the database ... There is a NON-cascading FK
constraint on the credit_card table
My environment:
Sun JDK 1.3
JBOSS 2.3 Beta (5-23-01 build) ... it has also been tested on JBOSS 2.2
final and still fails
PostgreSQL 7.1.2 on Redhat 7.1
Here's my java method ... i tried to make it as brief as possible (i cut out
most of the details of the exception handling for the rollback)
public TemplateWrapper serviceRequest(ServletParams params)
{
TransactionManager trans = null;
try{
trans =
(TransactionManager)getHome("java:/TransactionManager",TransactionManager.cl
ass);
log("Got txMgr interface");
trans.begin();
log("tx has begun...");
CreditCardHome cch =
(CreditCardHome)getHome("mybeans/CreditCard",CreditCardHome.class);
MemberCompanyAddressHome mcah =
(MemberCompanyAddressHome)getHome("mybeans/MemberCompanyAddress",MemberCompa
nyAddressHome.class);
CreditCard cc = cch.findByPrimaryKey(new Integer(3));
CreditCardRecord ccr = cc.getRecord();
MemberCompanyAddress mca = mcah.findByPrimaryKey(new
MemberCompanyAddressPK(ccr.billing_address_id));
ccr.billing_address_id = 49;
log("---CREDIT CARD BEFORE UPDATE---");
log(ccr.toString());
cc.setRecord(ccr);
log("---CREDIT CARD AFTER UPDATE---");
log(cc.getRecord().toString());
log("---ADDRESS BEFORE DELETE---");
log(mca.getRecord().toString());
mca.remove();
log("ADDRESS RECORD REMOVED!");
trans.commit();
log("tx committed...");
}
catch(Exception e){
log("Exception during transaction block! Attempting rollback..." + e);
e.printStackTrace();
trans.rollback();
log(LOG_ERROR,"Rollback successful");
}
return null;
}
Here's the output to the screen:
lookup name: java:/TransactionManager
Got txMgr interface
tx has begun...
lookup name: tradeim/CreditCard
lookup name: tradeim/MemberCompanyAddress
---CREDIT CARD BEFORE UPDATE---
credit_card_id = 3
member_company_id = 106
credit_card_expiration = 2004-04-01
credit_card_number_encoded = blah blah
billing_address_id = 49
credit_card_status = 1
---CREDIT CARD AFTER UPDATE---
credit_card_id = 3
member_company_id = 106
credit_card_expiration = 2004-04-01
credit_card_number_encoded = blah blah
billing_address_id = 49
credit_card_status = 1
---ADDRESS BEFORE DELETE---
member_company_address_id = 323
member_company_address_type = 3
member_company_address1 = asdf
member_company_address2 = asdfasdf
member_company_city = asdfasdf
member_company_zipcode = asdfsadf
member_company_state = ALB
member_company_id = 106
Exception during transaction block! Attempting
rollback...javax.ejb.RemoveException: Could not remove id=323
javax.ejb.RemoveException: Could not remove id=323
at
org.jboss.ejb.plugins.jaws.jdbc.JDBCRemoveEntityCommand.execute(JDBCRemoveEn
tityCommand.java:56)
at
org.jboss.ejb.plugins.jaws.JAWSPersistenceManager.removeEntity(JAWSPersisten
ceManager.java:168)
at
org.jboss.ejb.plugins.CMPPersistenceManager.removeEntity(CMPPersistenceManag
er.java:470)
at org.jboss.ejb.EntityContainer.remove(EntityContainer.java:331)
at java.lang.reflect.Method.invoke(Native Method)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invoke(EntityContainer.ja
va:692)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invoke(EntitySynchron
izationInterceptor.java:208)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invoke(EntityInstanceInterce
ptor.java:186)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:133)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.
java:298)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:99)
at
org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:19
0)
at
org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:195)
at org.jboss.ejb.EntityContainer.invoke(EntityContainer.java:323)
at
org.jboss.ejb.plugins.jrmp.server.JRMPContainerInvoker.invoke(JRMPContainerI
nvoker.java:480)
at
org.jboss.ejb.plugins.jrmp.interfaces.GenericProxy.invokeContainer(GenericPr
oxy.java:335)
at
org.jboss.ejb.plugins.jrmp.interfaces.EntityProxy.invoke(EntityProxy.java:13
3)
at $Proxy98.remove(Unknown Source)
at
mypkg.DBManipulatorServlet.serviceRequest(DBManipulatorServlet.java:64)
Rollback successful
This is what shows up in the PostGres log:
ERROR: <unnamed> referential integrity violation - key in
member_company_address still referenced from credit_card
NOTICE: current transaction is aborted, queries ignored until end of
transaction block
Executing the appropriate UPDATE and DELETE queries from the psql prompt
goes smoothly so i'm pretty sure that the problem is that they are executing
under different DB connections and therefore can't see one another's changes
... (hence the FK integrity error)
Am i doing something wrong or is this a bug?
Thanks in advance.
-Dave
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-user