Its already there on above code below the title 'SqlMapConfig.xml'.
Or do you need anything else?
Main Topics
Browse All TopicsHi,
I have 2 tables CUSTOMER and DEPENDENT.
In CUSTOMER table the primary key is cust_id which is foreign key to DEPENDENT table.
I would like to make insert to both tables together as a batch and also if one fails than other must roll back.
If I remove the constraints of having cust_id as a foreign key to DEPENDENT table than both insert works fine as required, it gets committed together and if any of it fails than none of the transaction will commit.
But as soon as I have two tables related, it works fine for first insert to CUSTOMER table, when I make a call to insert() statement, it does not commit yet, but when it reaches second insert() stmt to DEPENDENT table it throws below exception:
-- The error occurred in org/nexweb/qol/gcc/ibatis/
--- The error occurred while applying a parameter map.
--- Check the insertCustomerDependent-In
--- Check the statement (update failed).
--- Cause: java.sql.SQLException: ORA-02291: integrity constraint (DEPENDENT_CUST_ID_FK) violated - parent key not found
Can you check what am I missing ? I have also tried using SqlMapSession explicitly opening session and do all transaction but did not work.
I have been trying since last 2 days, please help me out.
Here is my code:
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Looks like the posting is cutting my code, Herer is the iBatis xml. Customer.xml is for CustomerService class and CustomerVehicle.xml is for CustomerVehicleService class. Also sending some more code:
CustomerService
public class CustomerService extends CommonService
{
private CustomerDAO customerDAO;
public CustomerService(CustomerDA
super(customerDAO);
this.customerDAO = customerDAO; }
public Integer insertCustomer(CustomerVO customerVo) throws DataAccessException {
return customerDAO.insertCustomer
}
public Integer insertCustomerDependent(Cu
return customerDAO.insertCustomer
}
CustomerAction.java
CustomerService customerService = SpringBeans.getCustomerSer
try
{ // retrieve cust_id from QOL_CUSTOMER using qol_customer_seq.NEXTVAL
custId = customerService.getCustome
customerService.startTrans
// start batch process
customerService.startBatch
// insert record into QOL_CUSTOMER table (add to batch process)
customerService.insertCust
// retrive dependent first/last name for insertion check to QOL_DEPENDENT tabel
String custDepFirstName = customerPersonalForm.getDe
String custDepLastName = customerPersonalForm.getDe
// insert into DEPENDENT table only if dependent first/last name enterd on the form
if (StringUtils.isNotBlank(cu
{
customerDependentVo.setCus
// set CustomerDependentVO to CustomerVO only if dependent first/last name exist and
// record to DEPENDENT is going to be inserted in for this customer id
customerVo.setCustomerDepe
// insert record into DEPENDENT table (add to batch process)
customerService.insertCust
}
// insert record into VEHICLE table (add to batch process)
customerVehicleService.ins
// execute batch
customerService.executeBat
// end batch process
customerService.commitTran
}
catch(SQLException sqlEx)
{ ........... }
finally { try { customerService.endTransac
catch(SQLException sqlEx) {
errors.add(ActionErrors.GL
logger.error(ExceptionUtil
You're getting custId from a sequence and I assume that it is the primary key of the Customer? But you aren't setting that value on your CustomerVO object before inserting it. So when you insert the CustomerDependentVO object with the generated custId set on it, the database is complaining that you have violated a foreign key constraint.
I appreciate your time to looking to the issue.
What you understood about the process is correct but I AM actually setting the value of custId in CustomverVO. Sorry, I accidently cut that code when I posted in comment. But I do set that. Also I removed the batch process statements from code as I am not executing same statement repeatedly. Here is my latest method. Whichs is still behaving the same. Not letting me get by second insert statement and throwing the same
--- Cause: java.sql.SQLException: ORA-02291: integrity constraint (DEPENDENT_CUST_ID_FK) violated - parent key not found
Shot in the dark, but shouldn't this:
<bean id="customerDao" class="org.nexweb.qol.gcc.
<property name="sqlMapClient">
<ref bean="sqlMapClient"/>
</property>
</bean>
be this:
<bean id="customerDao" class="org.nexweb.qol.gcc.
<property name="sqlMapClient">
<ref bean="sqlMapClientTemplate
</property>
</bean>
Ok. I guess I meant it but didn't say that you would need to change the type of the property in your DAO class. It seems to me the pattern is supposed to be that a SqlMapClient is injected into a SqlMapClientTemplate which is injected into your DAOs. I found some pointers elsewhere indicating that this could potentially be a problem (if you use the SqlMapClient directly).
Business Accounts
Answer for Membership
by: objectsPosted on 2009-03-09 at 18:07:45ID: 23842777
can u post your mapping config