• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Unique Key Violation While Doing Multiple Updates And Create in EJB

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All,

I am using oracle 9i and Weblogic 7.0. I have a table that has a unique key constraint on one column , say 'Col1' and i am using a CMP to read,create and update data in this table. The problem description is as follows.

I have JTable that display the data from the above said table. The user can modify the existing data and insert new data that will be reflected in the DB using the CMP. Let us say the following are displayed
ROW1
-------
Col1 : 3
Col2 : 'ABC'
Col3 : 1 (Primary key in the table)

Now the user modifies the above row and inserts a new record. Now the following will be the display

ROW1 (Modified)
----------
Col1 : 4
Col2 : 'ABC'
Col3 : 1 (Primary key in the table)

ROW2 (New)
-----------
Col1 : 3
Col2 : 'DEF'
Col3 : 2 (Primary key in the table)

When the above data is saved i do the following in the Code

a) Session Bean
---------------
For (all the data in the Jtable)
{
try
{
home.findByPrimaryKey(Col3);
remote.update(Col1,Col2);
}
catch(FinderException fe)
{
home.create(Col1,Col2,Col3);
}
}


When the above code is run During the first loop the update runs succesfully (i.e update old value of 3 with 4 ) but during the 2nd loop the create (i.e Insert new value 3) gives me the unique key violated exception. The following is the stack trace
-------------------------------------------------------------

<Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010049> <EJB Exception in method: ejbPostCreate: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated

java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1892)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:1093)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:2130)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:2013)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:2869)
at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:608)
at weblogic.jdbc.jts.Statement.executeUpdate(Statement.java:509)
at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.__WL_create(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1435)
at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.ejbPostCreate(TerminalPaymentsCMP_kbdoop__WebLogic_CMP_RDBMS.java:1353)
at java.lang.reflect.Method.invoke(Native Method)
at weblogic.ejb20.manager.DBManager.create(DBManager.java:1023)
at weblogic.ejb20.manager.DBManager.localCreate(DBManager.java:904)
at weblogic.ejb20.internal.EntityEJBLocalHome.create(EntityEJBLocalHome.java:180)
at de.dl.ucs.contract.entity.TerminalPaymentsCMP_kbdoop_LocalHomeImpl.create(TerminalPaymentsCMP_kbdoop_LocalHomeImpl.java:73)
at de.dl.ucs.contract.helperclasses.SubsegmentMaintanence.saveTerminalPayments(SubsegmentMaintanence.java:697)
at de.dl.ucs.contract.controller.SubsegmentSL.saveSubsegmentDetails(SubsegmentSL.java:570)
at de.dl.ucs.contract.controller.SubsegmentSL.processFinanceSubsegmentSave(SubsegmentSL.java:1601)
at de.dl.ucs.contract.controller.SubsegmentSL_kgzv4j_EOImpl.processFinanceSubsegmentSave(SubsegmentSL_kgzv4j_EOImpl.java:498)
at de.dl.ucs.contract.events.FinanceSubsegmentBEH.saveSubsegmentDetails(FinanceSubsegmentBEH.java:749)
at de.dl.ucs.contract.events.FinanceSubsegmentBEH.processEvent(FinanceSubsegmentBEH.java:232)
at de.dl.ucs.framework.flowcontroller.ControllerBean.delegateAction(ControllerBean.java:229)
at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl.delegateAction(ControllerBean_riqvk4_EOImpl.java:46)
at de.dl.ucs.framework.flowcontroller.ControllerBean_riqvk4_EOImpl_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:441)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerRef.java:114)
at weblogic.rmi.internal.BasicServerRef$1.run(BasicServerRef.java:382)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServiceManager.java:726)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.java:377)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest.java:30)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:234)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:210)
>
<Oct 25, 2004 11:36:22 AM IST> <Info> <EJB> <010051> <EJB Exception during invocation from home: de.dl.ucs.contract.controller.SubsegmentSL_kgzv4j_HomeImpl@3c8d34 threw exception: javax.ejb.TransactionRolledbackLocalException: EJB Exception:; nested exception is: java.sql.SQLException: ORA-00001: unique constraint (UAT_CYCLE2_1.UK_PYMT_DET_TX) violated
-------------------------------------------------------------------------

Please help me with this, as far as i am concerned since both update and create is in the same transaction the update on the row must be visible to the create and hence there shouild not be any problem.....

thanks in advance
Shanki
 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to insert record in FinderException is not a good coding style
You go into trouble when Finder Exceptiion is raised
and since you dont have EJB Object handle and still trying to insert a row
thats why you get that exception
 
Shanki Narayanan
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guarav,

Thanks for the response. I agree that inserting a record in the FinderException is not a good coding style.But then the other statement regarding the EJB OBject Handle is not convincing or rather i need more explanation on this.

Thanks
Shanki
 
incandescent light gives off an efficient form of heat. You must be THIS smart to ride this ride. Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic