[xwiki-users] Hibernate exceptions when saving documents and objects
Hi, I have a groovy script in a page, that loads some data and create pages and objects with it. Basically for each input data 2 new documents are created, each with 2 new objects inside (one a custom class, and one for tags "XWiki.TagClass"). For most documents there is no problem, while for some I get the following kind of exceptions (always for one of the classes, never for the other) : Error number 3201 in 3: Exception while saving document MailArchive. MMKSonLinuxpatch22-01 Wrapped Exception: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xpn.xwiki.objects.DateProperty#2009-09-14 15:57:26.0] The exact same date string is used to save another document/object without any problem (the Date fields have exactly same pattern format). I use the same SimpleDateFormat for all, and the patterns in the class are copy-paste, so why is it ok for one and failure for the other ? It's not always a DateProperty that cause issues, it can also be Strings or LargeStrings. I tried to delete my custom class and recreate it, purge all created documents (with doc.delete()), and also to purge all entries that were left even after delete(), directly in database (in tables xwikidoc, xwikiobjects, xwikistrings, xwikilargestrings, xwikidates and xwikirecyclebin), but it seems the same input data will always have document.save() fail this way. It seems it's always the second save() for an input data that can fail. This second save() targets a different document, object and class, and it's not the same groovy variables either. Could it happen that the first save() is not completely finished and there is some problem with tables updates ? Would I have something else to do to make sure previous transaction is finished ? I believe it must be something in the data, but it's only strings, largestrings and a date, so I don't know how to investigate more... Thanks for any help, Jeremie PS : I'm on XWiki 2.0.3, MySQL 5.1.38, Linux RH Rel 4
I suspect you have used some method setStringValue where you should have used setDateValue Ludovic Envoyé de mon iPhone Le 25 nov. 2009 à 07:44, Jeremie BOUSQUET <[email protected]> a écrit :
Hi,
I have a groovy script in a page, that loads some data and create pages and objects with it. Basically for each input data 2 new documents are created, each with 2 new objects inside (one a custom class, and one for tags "XWiki.TagClass").
For most documents there is no problem, while for some I get the following kind of exceptions (always for one of the classes, never for the other) :
Error number 3201 in 3: Exception while saving document MailArchive. MMKSonLinuxpatch22-01 Wrapped Exception: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xpn.xwiki.objects.DateProperty#2009-09-14 15:57:26.0]
The exact same date string is used to save another document/object without any problem (the Date fields have exactly same pattern format). I use the same SimpleDateFormat for all, and the patterns in the class are copy-paste, so why is it ok for one and failure for the other ? It's not always a DateProperty that cause issues, it can also be Strings or LargeStrings. I tried to delete my custom class and recreate it, purge all created documents (with doc.delete()), and also to purge all entries that were left even after delete(), directly in database (in tables xwikidoc, xwikiobjects, xwikistrings, xwikilargestrings, xwikidates and xwikirecyclebin), but it seems the same input data will always have document.save() fail this way. It seems it's always the second save() for an input data that can fail. This second save() targets a different document, object and class, and it's not the same groovy variables either. Could it happen that the first save () is not completely finished and there is some problem with tables updates ? Would I have something else to do to make sure previous transaction is finished ?
I believe it must be something in the data, but it's only strings, largestrings and a date, so I don't know how to investigate more...
Thanks for any help,
Jeremie
PS : I'm on XWiki 2.0.3, MySQL 5.1.38, Linux RH Rel 4 _______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
I think I understand... Currently what I am doing is : doc.use(doc.newObject("MyClass")) doc.set("date", sdf.format(mydate) ) ... doc.save() With "mydate" being a Date. I think I did it because doc.set("date", new Date() ) was not working. It works with the formatted string, and only if format in the SimpleDateFormat sdf is the same as in the Object "date" field, which convinced me it was correct. Do you mean I should give doc.set() a java.util.Date parameter instead of a String ? From the code, it looks like I should...
The same exception occurs for either : doc.set("date", sdf.format(mydate)) doc.set("date", mydate) // mydate is java.util.Date obj.set("date", mydate) // same for sdf.format(mydate) of course Here is a longer log after increasing log level : DEBUG jdbc.AbstractBatcher - about to open PreparedStatement (open PreparedStatements: 0, globally: 0) DEBUG hibernate.SQL - update xwikidates set XWS_VALUE=? where XWS_ID=? and XWS_NAME=? DEBUG jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) ERROR .AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xpn.xwiki.objects.DateProperty#2009-09-14 15:57:26.0] at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1769) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2412) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2312) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2612) at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:96) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279) If I have a look in xwikidates, of course the date is not added for this object, but though I doc.delete()-ed all created documents before retrying, there is in this table a date property from an already deleted document (another one). So I tried again deleting all "rests" in xwikiobjects, xwikidates, xwikilargestrings ... and so on, and also restarting the tomcat container. Now loading the same input data and calling save() results in this : DEBUG hibernate.SQL - update xwikistrings set XWS_VALUE=? where XWS_ID=? and XWS_NAME=? DEBUG jdbc.AbstractBatcher - about to close PreparedStatement (open PreparedStatements: 1, globally: 1) ERROR .AbstractFlushingEventListener - Could not synchronize database state with session org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.xpn.xwiki.objects.StringProperty#<?xml version="1.0" encoding="UTF-8"?> <messageid><[email protected] <lt%[email protected]>></messageid> ] It fails on a different property (messageid), which in this case is the first property saved. It's merely a short string going into xwikistrings, so I don't see how I could set it differently ? I wonder if it could not be due to hibernate cache, or previous transaction not being finished ? I really don't understand what's happening here... When it was failing on the "date" property, the "messageid" was correctly set, so I'm not sure it related to the content of the properties I try to set, but to what ?
Got it ! :) I realized that there was "update" requests for not-working properties, whereas good ones were doing "insert", which is ok because it's a new object. I found a bunch of properties for my particular object id in "xwikiproperties". After purging them and restarting container, my object saves successfully. What I do not understand, is how this could happen ? I still have to test it for all my input data...
participants (2)
-
Jeremie BOUSQUET -
Ludovic Dubost