PDA

View Full Version : Gilead/hibernate4gwt integration



robertlight
20 Nov 2009, 8:56 AM
I have a basic question on how I update a javabean in a model.

I have a Grid with a StoreListener which updates data on the server via hibernate4gwt

I get the bean out of the model via model.getBean() and send it to the server. In the client, bean.getVersion() returns Integer(1)

The server does a session.saveOrUpdate(bean) using gilead/hibernate4gwt

bean.getVersion() now returns Integer(2)

I send the bean back to the client.

Then the client changes the bean and sends it back to the server (it's getVersion() still returns Integer(1)

and the session.saveOrUpdate(bean) throws a StaleObjectStateException

which is correct...because the bean.getVersion() should have been Integer(2)


My problem is that there is no way to say model.setBean(bean) to update the model in the client when the bean is successfully stored on the server.

Either I'm not using the framework properly (very possible) or this is a shortcoming.

Can anyone help?

thanks.

sven
20 Nov 2009, 9:00 AM
I would try to debug the code. Does the bean received in the client really returns 2? Or does it only receive 2 on the server.

robertlight
20 Nov 2009, 9:13 AM
I have put it thru the debugger.... hibernate4gwt is doing the right thing...the bean that is coming in from the client is indeed the wrong "version". The problem I'm having is that I don't see a way to update the client object with the proper version.

Note: when the bean is sent back to the client via the "onSuccess(Object bean)" method...the bean comes back with bean.getVersion() returning the proper: Integer(2).

but there is no way with GXT to update the model....I would be looking for something like model.setBean(bean)....but it isn't there.

sven
20 Nov 2009, 9:19 AM
You can great a new one with the BeanModelFactory.

You can also use JSNI to access the protected setBean method.

robertlight
20 Nov 2009, 12:35 PM
store.update( BeanModelLookup.get().getFactory(bean.getClass()).createModel(bean));

did the trick....thank you...it might be nice to have a convenience method somewhere obvious to make this a bit more apparent.

It's just a "tad" on the side of hibernate-black-magic.

Thanks!