Partially flushing

3 views
Skip to first unread message

SimonV

unread,
May 13, 2011, 5:46:19 AM5/13/11
to flextrine
Hi,

On this project I'm working on, I make use of tabs. On every tab there
is the possibility to save the entities that are displayed on that
tab. But when I call flush() on the Entitymanager, all the pending
changes are saved to the database. Would there be a way do let every
tab has its own UnitOfWork so I can decide which unit (tab) needs to
be written tot de database?
Somebody familiar with this?

Dave Keen

unread,
May 14, 2011, 9:25:21 AM5/14/11
to flex...@googlegroups.com
Hey Simon,

The way to deal with this situation in Flextrine is to use the
detach/detachCopy and merge methods. For example, this is how I would
implement a popup with a save and cancel button (which is quite similar
to your use case).

Supposing the the popup happens to edit a managed entity called
managedEntity, I would first do:

detachedEntity = em.detachCopy(managedEntity)

This gives me a complete copy of managedEntity, but the crucial thing is
that this entity is now detached, which means that I can make changes to
it without anything getting added to the UnitOfWork. On-demand loading
and bi-directional association management should still work on the
detached entity.

When I want to save the entity I do:

em.merge(detachedEntity);
em.flush();

Note that this is very recent functionality, so you'll need to work off
the master branch to get this feature.

Good luck!

Dave Keen
http://www.actionscriptdeveloper.co.uk

> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 10.0.1375 / Virus Database: 1500/3635 - Release Date: 05/13/11
>
>

Simon Vanherweghe

unread,
Jun 7, 2011, 4:44:06 AM6/7/11
to flextrine
Thanks,

But when merging, I get an error.

The isEntity function in the EntityUtil class gets the newValue (not
the entity itself) the describeType fails on this.
This kind of make sense because in the onPropertyChange in
EntityRepository we get this:

// Sometimes using detachCopy can mean we have a property change from
one instance to another, whilst the ids remain the same. This should
not trigger a PropertyChange.
if (e.newValue && e.oldValue && EntityUtil.isEntity(e.newValue) &&
EntityUtil.hasId(e.newValue) && EntityUtil.getUniqueHash(e.oldValue)
== EntityUtil.getUniqueHash(e.newValue))
return;

I'm working on the 14d5193 release (2011-06-04)


On 14 mei, 15:25, Dave Keen <d...@ruffness.com> wrote:
> Hey Simon,
>
> The way to deal with this situation in Flextrine is to use the
> detach/detachCopy and merge methods.  For example, this is how I would
> implement a popup with a save and cancel button (which is quite similar
> to your use case).
>
> Supposing the the popup happens to edit a managed entity called
> managedEntity, I would first do:
>
> detachedEntity = em.detachCopy(managedEntity)
>
> This gives me a complete copy of managedEntity, but the crucial thing is
> that this entity is now detached, which means that I can make changes to
> it without anything getting added to the UnitOfWork.  On-demand loading
> and bi-directional association management should still work on the
> detached entity.
>
> When I want to save the entity I do:
>
> em.merge(detachedEntity);
> em.flush();
>
> Note that this is very recent functionality, so you'll need to work off
> the master branch to get this feature.
>
> Good luck!
>
> Dave Keenhttp://www.actionscriptdeveloper.co.uk

Dave Keen

unread,
Jun 7, 2011, 5:11:05 AM6/7/11
to flex...@googlegroups.com
That's odd - I am using detachCopy and merge throughout my project without problems so it definitely should work. Can you please raise an issue in github with any relevant info and the exact error you are getting and I'll take a look.

Cheers,

Dave

Simon Vanherweghe <simon.va...@gmail.com> wrote:

--
Sent from my Android phone with K-9 Mail.

Reply all
Reply to author
Forward
0 new messages