13 Replies Latest reply: Sep 16, 2010 8:06 AM by NickH77 RSS

    How to do Unique Key Validation

    Paul (MITsa)
      ADF 11, ADF BC
      I might be missing something but how do you add a validator for an unique key ?

      I have an unique key defined on the DB, this unique key has nothing to do with the primary key.
      (Its checking that a code is unique)

      In the validators on the entity object I can set an unique key validator but it only lists the
      primary key for the check definition not the unique key....

      The unique key on the DB is working as I get a nice constraint violation error, so how do I
      either add a validator for a unique key or at least trap the error in order to display a user friendly message.

      Regards
      Paul
        • 1. Re: How to do Unique Key Validation
          Timo Hahn
          Go to the EO, open the attribute section and edit the attribute you want to be unique. In the dialog set the check mark on the Unique ceckbox and save your work.
          This should insert a unique constraint for the attribute.

          Timo
          • 2. Re: How to do Unique Key Validation
            Paul (MITsa)
            The EO attribute already has "unique" checked due to the unique key on the database...

            Paul
            • 3. Re: How to do Unique Key Validation
              John Stegeman
              Hello Paul,

              My recommendation would be to leave the unique constraint validation in the DB. Have a read of section 37.8.3 (updated for 11g, in 10g it's 33.8.3) of the Fusion Developer's Guide, where you will find out how to provide your own nice error messages instead of the ugly constraint violation one.

              Best,

              John
              • 4. Re: How to do Unique Key Validation
                Paul (MITsa)
                Hello John

                Don't quite know how I missed that chapter, and its not even Friday :-)
                Thanks for the info.

                Regards
                Paul
                • 5. Re: How to do Unique Key Validation
                  John Stegeman
                  Paul,

                  No worries. My top three suggestions for people using ADF, by the way, include:

                  1). Read the developer's guides (Fusion Developers Guide, Web User Interface Developers Guide)
                  2). Read them again
                  3). Go to 2.

                  ;)

                  Seriously, I generally scan the documents from cover-to-cover once or twice to get a feel for what is in there. I read each chapter through. Most of the information doesn't stick in my brain at all, some of it I conceptually understand but cannot see a use for yet, some of it is really useful, etc. Even for things in the first two categories (stuff that I don't really understand nor see the use for initially) - the fact that the information is there sticks in my brain - that way, when the time comes when I need the information, I usually vaguely remember that such a chapter exists and go hunting for it.

                  Best,

                  John
                  • 6. Re: How to do Unique Key Validation
                    726472
                    Hi

                    Can you descripe how set error message for unique constraint ?
                    • 7. Re: How to do Unique Key Validation
                      John Stegeman
                      [url http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcadvgen.htm#sthref2948]read the documentation

                      John
                      • 8. Re: How to do Unique Key Validation
                        726472
                        Hi,

                        Thanks.

                        But i would like to display a custom message when any database table constraint is violated. I added a custom class which extends ListResourceBundle class. It helps to decode the JBO errors but not ORA errors. When any constraint is violated, it shows two error message (JBO and ORA). How to customize ORA message?
                        • 9. Re: How to do Unique Key Validation
                          NickH77
                          Check this out: http://it.toolbox.com/blogs/jjflash-oracle-journal/reporting-ora20xxx-errors-with-adf-bc-the-details-33094
                          • 10. Re: How to do Unique Key Validation
                            726472
                            Thanks for responce

                            I try it but it still appear ORA error
                            • 11. Re: How to do Unique Key Validation
                              NickH77
                              Did you use the code as is? ;)


                              You need to adapt it a bit for your requirements:
                              // remove this, to catch all ORA- DML-related errors
                              if (sqlErrorCode >= 20000 && sqlErrorCode <= 20999) {
                              }
                              • 12. Re: How to do Unique Key Validation
                                726472
                                Ya i know, i change it as my ORA error,

                                but what his mean about
                                CommonAppException appEx =
                                                            new CommonAppException(message,
                                                                                   String.valueOf(sqlErrorCode),
                                                                                   null); 
                                                        newEx = appEx;
                                CommonAppException is not defined?

                                and where i must sit this code? i create class and extend it for oracle.jbo.server.DBTransactionImpl2 calss, is that true ?


                                Thanks
                                • 13. Re: How to do Unique Key Validation
                                  NickH77
                                  Read the post again: http://it.toolbox.com/blogs/jjflash-oracle-journal/reporting-ora20xxx-errors-with-adf-bc-the-details-33094 X-(

                                  I created my own subclass of JboException so that I could override getProductCode and use my own product code instead of "JBO". It is very short, and not worth including here. The only thing I don't like about the way I've implemented this is that I use a constructor that does not use a Resource Bundle to localize the message. I'll probably change that later.