2 messages in org.codehaus.grails.userRe: [grails-user] Interesting Hiberna...
FromSent OnAttachments
stuart claymanSep 13, 2007 9:55 am 
Graeme RocherSep 13, 2007 10:00 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [grails-user] Interesting Hibernate MessageActions...
From:Graeme Rocher (grae@yahoo.co.uk)
Date:Sep 13, 2007 10:00:22 am
List:org.codehaus.grails.user

Grails uses optimistic locking (or versioning) under the covers. This means that it allows concurrent modification to data (domain classes) but does a check at the last minute to see if someone else (another thread) has update the data before saving it

If someone else has updated the data you get a StaleObjectStateException

So what can you do? Well you can either catch the exception and then call "refresh()" on your object and try to re-concile the changes or in SVN at the moment you can use pessimistic locking (which is the same as "select ..for update" at the db level

def b = Book.get(10) b.lock() // lock it

..// do work

b.save()

The row that is represented by the object will be unlocked when the transaction is committed

Cheers

On 9/13/07, stuart clayman <scla@timeindexing.com> wrote:

I recently got this message when I hit a page.

I assume I am doing something wrong somewhere, but not being a Hibernate user I'm not entirely sure what caused it.

Any ideas anyone.

Here is the message and a bit of the stack trace:

Object of class [Media] with identifier [643]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Media#643] org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException: Object of class [Media] with identifier [643]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Media#643] Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Media#643]

at org.hibernate.persister.entity.AbstractEntityPersister.check(AbstractEntityPersister.java:1714) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2357) at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2257) at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2557) at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:92) at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000) at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:388) at org.codehaus.groovy.grails.orm.hibernate.support.GrailsOpenSessionInViewInterceptor.flushIfNecessary(GrailsOpenSessionInViewInterceptor.java:37) at org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor.postHandle(OpenSessionInViewInterceptor.java:170) at org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter.postHandle(WebRequestHandlerInterceptorAdapter.java:61) at org.codehaus.groovy.grails.web.servlet.GrailsDispatcherServlet.doDispatch(GrailsDispatcherServlet.java:247) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:736) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:396) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:350) at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)

-- View this message in context:
http://www.nabble.com/Interesting-Hibernate-Message-tf4437074.html#a12659153 Sent from the grails - user mailing list archive at Nabble.com.

--------------------------------------------------------------------- To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email