Note that there are some explanatory texts on larger screens.

plurals
  1. POJPA (Eclipselink impl) lazy fetch outside transaction
    primarykey
    data
    text
    <p>I'm using glassfish and Java EE 6. I have created a restful web service with Jersey that performs searching operations on a <code>Comment</code> table. Each comment has an <code>Author</code>.</p> <p>I have a <code>@Stateless</code>, <code>@Path('comments')</code> EJB listening on Http requests. I then have this method:</p> <pre><code>@GET @Path("search") @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED) public List&lt;Comment&gt; getComments(@QueryParam("criteria").....) </code></pre> <p>My JPA query fetches a bunch of comments. Each comment has an association to its Author, that is also fetched since it's not set to LAZY, but except for his ID, most of the Author's fields are not retrieved (e.g The Author's name) even though I tried setting them to <code>@Basic(fetch = FetchType.EAGER)</code>. This gets retrieved when I do something like:</p> <pre><code>comment.getAuthor().getName() </code></pre> <p>But this works if I am inside a transaction so the Persistence Context is alive throughout the execution of my method. However, I don't want to use a transaction here since this is just searching the Database and not changing any data (hence the <code>@TransactionAttribute(...NOT_SUPPORTED)</code>), so when I call the getter above I simply get a "null" (no data is fetched), and I don't know how to work this out.</p> <p>I don't want to use a Transaction, but I want Eclipselink to fetch the attributes of the Author eagerly.</p> <p>EDIT:</p> <p>Since I'm not within a transaction, put simply, what I want is for eclipselink to retrieve my "comment.author.name" field for every comment I get from my query.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload