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>&lt;blabla(a)titi.com
<lt%3Bblabla(a)titi.com>&gt;</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 ?