JSF, CDI, EJB + JPA and Transaction -


With the JEE 7 setup using JSF, CDI, EJB + JAPA, I took part in this issue "failed to start a collection". I got a solution but would like to confirm that this is a proper solution and I have understood it correctly.

Setup is basically:

JSF - & gt; CDI Bean - & gt; EJB3 - & gt; JPA

In the JSF page I basically:

  & lt; ui: Repeated value = "# {dishService.dishes}" var = "dish" & gt; & Lt; ui: Recurrence value = "# {dish.ingredients}" var = "components" & gt; # {ingredient.name} & lt; / UI: Repeat & gt; & Lt; / ui: Repeat & gt;   

cdi bean:

  @entententent @ named public class dish service {@ inject private database service local database service; Public listing & lt; Dish & gt; getDishes () {return database Service.getDishes (); }}   

EJB: @Stateless Public Class database service executes databaseService Local, DatabaseBaseRemote {@ PrestigeContacts (entity name = "distlist") Private unit management unit manager; Public listing & lt; Dish & gt; GetDishes () {Last Query Query = entityManager.createQuery ("Select D from Dish D"); Return query.getResultList (); }}

JPA unit dish:

  @OneToMany (mapped = "dish", cascade = cascade type. Parasite, orphan removals = true) Private listing & lt; Component & gt; Components = Archive.   

More components:

  @ManyToOne personal dish dish;   

This creates an error running:

Failed to start a collection of roles: the institution.Disclaimer could not start the proxy - No Sessions

I understand that this happens because the JTA Container managed transaction ends when EJB's public law getDishes () is complete. JPA institutions separate and the session closes, and JSF is not more likely to freely load the content in the page.

After some research, it seemed that the most acceptable solution for this is Joint Fellowship

  entityManager Changed to .createQuery ("Dish DeJoin Fate D. Choose Separately with Content");   

And the problem is resolved. I have to add without DISTINCT , the query produces all the dishes and cartesian products of the material, which I hope.

Then finally the question: did I understand the problem is correct and add appropriate solution ?

Yes, setting is the most appropriate way to get involved on the query.

You can also use the Entity Graph, to do a new feature fitting in JPA 2.1.

The reason for this is that the transaction starts with your CDI Managed Bean, will call JSF Managed Bean, but there are many wrappers around it. It is trying to bring the value out of the transaction.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -