Hi. I've answered this also on the db4o forum. This is a copy of my answer:
Which version of db4o are you using? To me that looks like some kind of regression / accidental API breakage. Instead of the UniqueFieldValueConstraintViolationException the EventException is thrown. The unique-field detection is just another event handler. So it looks like the original UniqueFieldValueConstraintViolationException is hidden by the event- exception Try to catch the EventException an check if the .getCause() is a UniqueFieldValueConstraintViolationException. In general the UniqueFieldValueConstraintViolationException should be the last 'barrier' before violating the constrain. If you know that you probably will insert a doublicate then I recommend to first check if that id isn't used yet. On Jun 22, 3:29 pm, imran ali <imran...@gmail.com> wrote: > Hi All, > > in one of my application i have been downloading lots of data from > server and then saving in to db4o. > > in my case i am saving 200 objects of Recipe class in loops, and on > every 200 store, i am using commit(). > > in Recipe Class i have define id as unique as follows > > configuration.common().add(new > UniqueFieldValueConstraint(Recipe.class, "id")); > when i have been commiting after 200 stor,e it has been throwing > exception,code at comit is as follows > > public void commitdb() > > { > > try > > { > > oc.commit(); // oc is object of objectContainer > > } > > catch(UniqueFieldValueConstraintViolationException exp) > > { oc.rollback(); } > > } > > Still i am getting exception as follows, (i am using db4o on Android) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): > com.db4o.events.EventException > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.events.EventRegistryImpl.withExceptionHandlingInCallback(EventRegistryImpl.java: > 283) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.events.EventRegistryImpl.commitOnStarted(EventRegistryImpl.java: > 121) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.LocalTransaction.dispatchCommittingCallback(LocalTransaction.java: > 90) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.LocalTransaction.commit(LocalTransaction.java:65) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.LocalTransaction.commit(LocalTransaction.java:59) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.LocalObjectContainer.commit1(LocalObjectContainer.java: > 104) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.IoAdaptedObjectContainer.commit1(IoAdaptedObjectContainer.java: > 171) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.ObjectContainerBase$3.apply(ObjectContainerBase.java: > 403) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.ObjectContainerBase$3.apply(ObjectContainerBase.java: > 401) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.ObjectContainerBase.asTopLevelCall(ObjectContainerBase.java: > 427) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.ObjectContainerBase.commit(ObjectContainerBase.java: > 401) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.ExternalObjectContainer.commit(ExternalObjectContainer.java: > 39) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.altaworks.kokaihop.db4o.RecipeProvider.commitdb(RecipeProvider.java: > 42) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.altaworks.kokaihop.ui.TakeoffActivity$4.run(TakeoffActivity.java: > 707) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > java.lang.Thread.run(Thread.java:1096) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): Caused by: > java.lang.NullPointerException > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.constraints.UniqueFieldValueConstraint > $1.ensureSingleOccurence(UniqueFieldValueConstraint.java:59) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.constraints.UniqueFieldValueConstraint > $1.onEvent(UniqueFieldValueConstraint.java:96) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.events.Event4Impl.trigger(Event4Impl.java:78) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.events.EventRegistryImpl > $4.run(EventRegistryImpl.java:123) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.foundation.DynamicVariable.with(DynamicVariable.java:54) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.InCallback.run(InCallback.java:24) > > 06-22 18:30:41.568: ERROR/AndroidRuntime(14823): at > com.db4o.internal.events.EventRegistryImpl.withExceptionHandlingInCallback(EventRegistryImpl.java: > 279) > > What should be solution, i have to store all 200 objects, and if > already object is present with same id, then over-write with new > object? > > Regards > Imran ali -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en