Friday, June 14, 2013

Re: RequestFactory Issue 6115

Hello Thomas,

Open Session In View is the right approach to go for. Thank you for this advice!
I have implemented it and it works fine now.

However, I have one question regarding OSIV-Pattern:
In the Hybernate example (see link below) they begin transaction before doFilter() and commit on transaction after it.
https://community.jboss.org/wiki/OpenSessionInView

I am using standard GWT setting with DataNucleus. For some reason it does not let me call em.getTransaction().begin(); and em.getTransaction().commit(); within the filter.
In my current implementation I can create EntityManager before doFilter()  and close it afterwards (this works), but cannot commit nor rollback transaction

Here is the error which I get when trying to open and commit the transaction:
org.datanucleus.exceptions.NucleusFatalUserException: Illegal argument
....
Caused by: java.lang.IllegalArgumentException: cross-group transaction need to be explicitly specified, see TransactionOptions.Builder.withXGfound both Element {
  type: "JobCategory"
  id: 1
}
 and Element {
  type: "JobCategory"
  id: 13
}

Do you have any Idea what might be the reason?
It must probably have something to do with my persistence.xml settings:

    <persistence-unit name="emajstor_persistence">
... some Entities
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>

Thank you in advance:

Nermin



Am Donnerstag, 13. Juni 2013 15:05:56 UTC+2 schrieb Thomas Broyer:


On Thursday, June 13, 2013 2:57:02 PM UTC+2, Nermin wrote:
Hello group,

Is the issue 6115 Fixed in GWT 2.5 or not??
http://code.google.com/p/google-web-toolkit/issues/detail?id=6115

My problem is that on a entity with recursive relation the ancestors are not loaded when calling with(ancestors).

Here is my code:

@Entity
public class JobCategory {
    // -- Recursive Relation mainCategory - SubCategories
    @OneToMany(mappedBy = "mainCategory", cascade = CascadeType.ALL)
    private Set<JobCategory> subCategories = new HashSet<JobCategory>();
    @ManyToOne
    private JobCategory mainCategory;

... Getters / Setters

    public static List<JobCategory> findAllJobCategories() {
        EntityManager em = EMFService.get().createEntityManager();
        try {
            Query query = em.createQuery("SELECT e FROM "+ JobCategory.class.getSimpleName() + " e ORDER BY i18nKey");
            return (List<JobCategory>) query.getResultList();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            em.close();
        }
        return new ArrayList<JobCategory>(); // Return empty list.
    }
}


When I call:
JobCategoryRequest jobCategoryReq = this.requestFactory.jobCategoryRequest();
Request<List<JobCategoryProxy>> req = jobCategoryReq.findAllJobCategories().with("subCategories");
req.fire(receiver);

... The call will return categories but without subcatgeories. (The list is always empty).
I checked the DB, it is all fine there.

Can it be that the Bug 6115 has not been fixed, even though its status says so, or am I doing something wrong here?

Have you checked whether the caller is called? if it is, does it return a populated set?

You're supposed to use an open-session-in-view (aka session-per-request) pattern with RequestFactory, rather than creating/closing an EntityManager in each service method. In this simple example (a single service method call in the RequestContext, with no shared object between the request –arguments– and the response), it shouldn't cause any harm except if you lazy-load your linked entities.


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate