Unless you implement some caching layer yourself, you will most likely
want to use the mentioned methods, and of course a request scoped (or
larger) entity manager or session. Once an entity is in the current
persistence context, a call to em.find() or session.get() will just
pull the value from the context. And, you should note that RF will
call Locator.find() on every entity it proxies back to the client,
including all those that were looked up as list when showing a page of
records, for example. So, for a simple list query, you end up with n +
1 db lookups (the original query and one for each entity in
Locator.find()) if you're not careful.
You might have to also be careful if you have FetchType.LAZY
attributes with such a locator. I do:
if (HibernateProxy.class.isAssignableFrom(clazz)) {
clazz = (Class<? extends VersionableEntity>) clazz.getSuperclass();
}
return entityManagerProvider.get().find(clazz, id);
Another gotcha, uncovered when dealing with RF, is that BeanValidation
can have issues with validating Hibernate proxies if the validation
annotations are applied to fields as opposed to getters. Beware,
always apply to getters!
Jesse
On Tue, Feb 7, 2012 at 2:08 PM, Eric Andresen <[email protected]> wrote:
> Jesse,
>
> Currently my find() methods are calling into some spring-managed DAOs,
> which in turn run a named query on the database to retrieve the object. I
> will try changing these to use the EntityManager directly and see if that
> helps.
>
> Thanks,
> Eric
> ---------------------------------------------------
> Eric Andresen
>
>
>
> On Tue, Feb 7, 2012 at 12:15 PM, Jesse Hutton <[email protected]>
> wrote:
>>
>> Eric,
>>
>> By flush you mean the primary object has it's values rest to the
>> persistent state in the db?
>>
>> What does your Locator#find() method look like? When using Hibernate
>> with RequestFactory, you should always use EntityManager.find() (or
>> the Hibernate Session equivalents) in Locator#find() because that will
>> prevent hitting the db multiple times for a given entity, which I'm
>> guessing might be part of the problem.
>>
>> Jesse
>>
>> On Tue, Feb 7, 2012 at 11:25 AM, Eric Andresen <[email protected]>
>> wrote:
>> > Stefan,
>> >
>> > In the past we have investigated FlushMode.COMMIT and
>> > FlushMode.MANUAL,
>> > but everything we have read about this is that Spring/Hibernate treats
>> > it
>> > only as a suggestion and not a rule, and it may still flush at
>> > inopportune
>> > times.
>> >
>> > We did bring in some consultants from SpringSource and asked them this
>> > question a few months ago, but they recommended against changing the
>> > FlushMode. They instead suggested either maintaining a strict order of
>> > operations or working with detached objects.
>> >
>> > Thanks,
>> > Eric
>> > ---------------------------------------------------
>> > Eric Andresen
>> >
>> >
>> >
>> > On Tue, Feb 7, 2012 at 6:44 AM, StefanR <[email protected]>
>> > wrote:
>> >>
>> >> Hi Eric,
>> >>
>> >> is setting the hibernate flush mode to COMMIT an option? That would
>> >> mean
>> >> that no flush is executed before running a query.
>> >>
>> >> Regards,
>> >> Stefan.
>> >>
>> >> --
>> >> You received this message because you are subscribed to the Google
>> >> Groups
>> >> "Google Web Toolkit" group.
>> >> To view this discussion on the web visit
>> >> https://groups.google.com/d/msg/google-web-toolkit/-/iw6cs7bEpbIJ.
>> >>
>> >> To post to this group, send email to
>> >> [email protected].
>> >> To unsubscribe from this group, send email to
>> >> [email protected].
>> >> For more options, visit this group at
>> >> http://groups.google.com/group/google-web-toolkit?hl=en.
>> >
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "Google Web Toolkit" group.
>> > To post to this group, send email to
>> > [email protected].
>> > To unsubscribe from this group, send email to
>> > [email protected].
>> > For more options, visit this group at
>> > http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google Web Toolkit" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/google-web-toolkit?hl=en.
>>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.