• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Question about create()

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all
I just think of when create a new record , need to validate the data and if the data is invlid, how can deal with this case.
I need create a new Exception and wrap it in the exception DuplicateKeyException???
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Lim,
Welcome to JavaRanch and this forum !

I just think of when create a new record , need to validate the data and if the data is invlid, how can deal with this case. I need create a new Exception and wrap it in the exception DuplicateKeyException???


Wouldn't it be better to throw some IllegalArgumentException (RuntimeException) in that case ? Or a class of your own extending IllegalArgumentException ? It wouldn't force you to change the method signature (you must not BTW), neither use an existing checked exception whose purpose is different.
Cheers,
Phil.
 
Lim YH
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Phil,
thanks for your answer, a runtime exception is right.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just my 2 cents worth, given its a new record why can't you validate
all the data before ever getting to the database side. You could
validate the data in you controller if you are using an MVC pattern
for your gui. The only exception you would have to handle at the
back end of the process would be a duplicate key exception which may
be in your interface provided by sun already.
 
Lim YH
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi bill
I think when I put the validate logic on client side, this mean the client side must know all fields of record and each field means what, I think it's not suitable for expanding. So I just do the validation on server side
Lim
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic