Not really a problem, I was just curious. There are lots of patterns for creating puesdo-puesdo-random-numbers, and it seems like using the database is expensive for that function.
It depends on the purpose of the random number and the scale and performance of the app I guess. It's really none of my business, I think random number patterns can be interesting and was curious. UUID can help if you are looking for an alternative in jdk 1.5+ -D On May 6, 2010, at 8:08 AM, t...@dds.nl wrote: > > i don't get the problem. > > you have an object with a field which is unique > > than make the object, save it using a dao, catch the exception. > if it is something with unique constrain than you know... > > > tibi > > > Quoting Juan Antonio Calderón <juan....@tecnosfera.org>: > >> Is not an object "key", is a property in a model java class, an unique field >> in the database :) >> >> I have to try it, to know if there is a duplicate field. >> >> Any other way? ;) >> >> Thanks everybody. >> >> 2010/5/6 Dustin Pearce <dustin_pea...@yahoo.com> >> >>> Are you generating a random number for the object "key" and then seeing if >>> its already there and trying again...and again...? Just curious. >>> >>> -D >>> >>> On May 5, 2010, at 7:17 PM, Juan Antonio Calderón wrote: >>> >>> Maybe DataIntegrityViolationException could be used, like in >>> UserManagerImpl.java? >>> >>> Thanks. >>> >>> 2010/5/6 Juan Antonio <juan....@tecnosfera.org> >>> >>>> >>>> Hello everybody. >>>> >>>> I have a problem. >>>> >>>> I generate a random field, that must be unique, and i need to catch the >>>> exception thrown in the save() method in the DAO. >>>> >>>> What is the exception thrown? Is an HibernateException, a >>>> RuntimeException...? >>>> >>>> I used to catch an ConstraintViolationException, could be this? >>>> >>>> Thanks. >>>> -- >>>> View this message in context: >>>> http://appfuse.547863.n4.nabble.com/Exception-thrown-when-a-unique-field-in-database-is-duplicate-tp2131915p2131915.html >>>> Sent from the AppFuse - User mailing list archive at Nabble.com. >>>> >>>> --------------------------------------------------------------------- >>>> To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net >>>> For additional commands, e-mail: users-h...@appfuse.dev.java.net >>>> >>>> >>> >>> >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net > For additional commands, e-mail: users-h...@appfuse.dev.java.net > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@appfuse.dev.java.net For additional commands, e-mail: users-h...@appfuse.dev.java.net