Paul,

please no attachments, as their is no guarantee that it won't be filtered out 
by spam filters, virus software, etc. Anyhow, here's a couple of general (not 
problem-specific) comments.

a) Don't use Castor from within a JSP. Iow, consider switching to any MVC 
framework available, e.g. Spring, Struts, etc.
b) With the use of such a framework, data validation could and should take 
place long before data is about to be persisted. Struts, for example, allows 
you to configure validation rules in various ways, as do other frameworks.

Now, getting more Castor specific.

a) Exception handling with Castor is not easy, but the way you've got it is 
slightly ambiguous. Personally, I'd use a try/catch-block as follows:

try {

   Database db = jdo.getDatabase();
   db.begin();

   ...

   db.commit ();
}
catch (Exception e) {
   try {
      db.rollback();
   }
   catch (PersistenceException e) {
      log.error ("problem rolling transaction back", e);
   }
   
   // some other, custom error handling
}
finally 
{
   try {
      db.close();
   }
   catch (PersistenceException e) {
      log.error ("problem closing Database instance", e);      
   }
}

This way you guarantee that you Database instance will be closed irrespective 
of whether you code finished successfully, or an exception had been 
thrown.

And finally, as to why you get a DuplicateKeyException, I have to pass. If 
you'd be willing to open a bug report and attach a JUnit test case (I could 
send you a template) that contains the most minimal code fragment to replay 
your problem, mapping file, SQL DDL, etc., I'd be willing to pick this up and 
test things thoroughly.

Thanks
Werner

On Wed, 10 Nov 2004 10:10:32 +0800, PAUL CHAN NCSI HK NCS wrote:

>Attached. 
>
>-----Original Message-----
>From: Werner Guttmann [mailto:[EMAIL PROTECTED] 
>Sent: Wednesday, November 10, 2004 3:17 AM
>To: [EMAIL PROTECTED]
>Subject: Re: [castor-user] DuplicateIdentityException Problem...
>
>
>Paul,
>
>can you please post the code as it stands currently. There's a couple of
>small issues I would want to assess first, before asking you to submit a bug
>
>report.
>
>Regards
>Werner
>
>On Tue, 9 Nov 2004 18:00:46 +0800, PAUL CHAN NCSI HK NCS wrote:
>
>>
>>I added db.rollback(); at the catch clause.. the problem still exists.
>>
>>-----Original Message-----
>>From: Bruce Snyder [mailto:[EMAIL PROTECTED] 
>>Sent: Tuesday, November 09, 2004 4:05 PM
>>To: '[EMAIL PROTECTED]'
>>Subject: Re: [castor-user] DuplicateIdentityException Problem...
>>
>>
>>PAUL CHAN NCSI HK NCS wrote:
>>
>>> I have a problem need your help. The problem exist when JDO is used at
>web
>>> application server.
>>> 
>>> The problem is similar to following JSP example
>>> 
>>>  
>>> 
>>> The OBDiseaseBean has one-to-many mapping to a child
>>> 
>>> table OBClinicalPresentation as a ArrayList inside OBDiseaseBean. 
>>> 
>>> The following code is try to add OBClinicalPresentation record to
>>> 
>>> the OBDiseaseBean, but the remark field size of of OBDiseaseBean
>>> 
>>> is too large Following exception is thrown
>>> 
>>>  
>>> 
>>> [code]
>>> 
>>> Nested error: org.exolab.castor.jdo.PersistenceException: Nested error:
>>> java.sql.SQLException: ORA-01401: inserted value too large for column
>>> 
>>> [/code]
>>> 
>>>  
>>> 
>>> Therefore, I remark the [b]bean.setRemk(b.toString());[/b] method on
>>coding
>>> and try to add the OBClinicalPresentation record again (Reload the JSP).
>>> Following Exception is thrown. 
>>> 
>>>  
>>> 
>>>  
>>> 
>>> [code]
>>> 
>>> Nested error: org.exolab.castor.jdo.DuplicateIdentityException: Duplicate
>>> identity found for object of type OBClinicalPresentation with identity :
>>an
>>> object with the same identity already exists in persistent storage
>>> 
>>> [/code]
>>> 
>>>  
>>> 
>>> Note that there is no [b]duplicated record[/b] exist at Database, but
>>> 
>>> JDO continues to throw DuplicateIdentityException until
>>> 
>>> I restart  web application server.
>>> 
>>> Therefore, how can i solve this [b]problem/error/bug ??[/b] :( 
>>.
>>>        // try to commmit
>>> 
>>>        db.commit();         
>>> 
>>>        db.close();
>>> 
>>>        out.println("Success");
>>> 
>>>                      
>>> 
>>>            } catch (Exception e) {
>>> 
>>>                      out.println(e.getMessage());
>>> 
>>>                      e.printStackTrace();
>>> 
>>>                      
>>> 
>>>            } finally {                 
>>> 
>>>                      
>>> 
>>>                      if( rs != null )
>>> 
>>>                                 rs.close();
>>> 
>>>                                 
>>> 
>>>                      if( query != null )
>>> 
>>>                                 query.close();
>>> 
>>>                                 
>>> 
>>>                      if( db != null && db.isActive() )
>>> 
>>> 
>>>                                 db.rollback(); 
>>> 
>>>                      else if( db != null )
>>> 
>>>                                 db.close();
>>> 
>>>            }
>>> 
>>
>>Paul,
>>
>>I believe that the DuplicateIdentityException is because the cache 
>>contains an item with the same identity because the failed commit is not 
>>properly rolled back. In the code aobve, the db.rollback() call should 
>>be taking place in the catch clause so that when an exception occurs 
>>during commit, the tx will be properly rolled back. The code above is 
>>calling db.rollback() in the finally clause and this is incorrect. 
>>Unless there's some other process calling db.close(), the db.isActive() 
>>call will always return true so it will try to call db.rollback() but 
>>there will be nothing to be rolled back. Try calling db.rollback() in 
>>the finally clause instead.
>>
>>Bruce
>>-- 
>>perl -e 'print 
>>unpack("u30","<0G)[EMAIL PROTECTED]&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'
>>
>>The Castor Project
>>http://www.castor.org/
>>
>>Apache Geronimo
>>http://geronimo.apache.org/
>>
>>
>>
>>----------------------------------------------------------- 
>>If you wish to unsubscribe from this mailing, send mail to
>>[EMAIL PROTECTED] with a subject of:
>>        unsubscribe castor-user
>>
>>
>>
>>----------------------------------------------------------- 
>>If you wish to unsubscribe from this mailing, send mail to
>>[EMAIL PROTECTED] with a subject of:
>>        unsubscribe castor-user
>>
>
>
>
>----------------------------------------------------------- 
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
>        unsubscribe castor-user
>
>



----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-user

Reply via email to