You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Rodolfo Cartas <ro...@gmail.com> on 2010/01/14 11:47:16 UTC

Wicket Wizards and Hibernate

Hi! I'm currently working on a wizard to modify a pojo extracted from  
a database with Hibernate. I don't want to commit any changes to the  
db before the user finishes the wizard, but the pojo loses reference  
to the original session. Shall I eagerly fetch the object to avoid any  
hibernate session reference exceptions?

Thanks,

Rodolfo

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket Wizards and Hibernate

Posted by Steve Swinsburg <st...@gmail.com>.
Hi,

Once you have the object built up, you could reattach it to the session with saveOrUpdate() which will figure out if it needs to insert or update. This assumes you are using the Spring Hibernate wrapper templates.

cheers,
Steve


On 14/01/2010, at 9:47 PM, Rodolfo Cartas wrote:

> Hi! I'm currently working on a wizard to modify a pojo extracted from a database with Hibernate. I don't want to commit any changes to the db before the user finishes the wizard, but the pojo loses reference to the original session. Shall I eagerly fetch the object to avoid any hibernate session reference exceptions?
> 
> Thanks,
> 
> Rodolfo
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 


Re: Wicket Wizards and Hibernate

Posted by nino martinez wael <ni...@gmail.com>.
I posted something about a shadowmodel.. In the end I did this :

						Model<Event> eventModel = new Model<Event>(
								(Event) SerializationHelper.clone((Event) model
										.getObject()));
						CompoundPropertyModel<Event> e = new CompoundPropertyModel<Event>(
								eventModel);
						EventWizard newWizard = new EventWizard(eventWizard
								.getId(), e) {
							@Override
							public void onFinish() {
								eventRepository.update(eventModel.getObject());
								eventWizard.setVisible(false);
							}
						};

This is the helper : import org.hibernate.util.SerializationHelper;

IT's working nicely the trick as you've discovered when the wizard are
over multiple pages..


2010/1/14 Rodolfo Cartas <ro...@gmail.com>:
> Hi! I'm currently working on a wizard to modify a pojo extracted from a
> database with Hibernate. I don't want to commit any changes to the db before
> the user finishes the wizard, but the pojo loses reference to the original
> session. Shall I eagerly fetch the object to avoid any hibernate session
> reference exceptions?
>
> Thanks,
>
> Rodolfo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Wicket Wizards and Hibernate

Posted by Martin Sachs <sa...@gmail.com>.
hi,

if you want to store the Objects at the end of the wizzard, you have to
reattach to the session with lock(NONE), else Entitymanager.merge will
save each step.

Alternativly you can open one transaction and merge (or saveOrUpdate)
after every step. On last step you can commit the transaction. I think
this is named conversation.

martin

Rodolfo Cartas schrieb:
> Hi! I'm currently working on a wizard to modify a pojo extracted from
> a database with Hibernate. I don't want to commit any changes to the
> db before the user finishes the wizard, but the pojo loses reference
> to the original session. Shall I eagerly fetch the object to avoid any
> hibernate session reference exceptions?
>
> Thanks,
>
> Rodolfo
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org