What do you mean by "need to access to the subjects field before closing the
em?". Do you mean, with the em,  retreive the list of subjects and the add
them to the list of books?. (That's a workaround, but it is not efficient),
It's supposed to retreive the books completly with their subjetcs also, I
might be doing something wrong in the Entities.

Please soome help.

On 18 January 2011 00:30, Stephen Johnson <onepagewo...@gmail.com> wrote:

> I don't do JPA, but If it's like JDO and you have lazy loading then don't
> you need to access the subjects field before you close your entity manager
> to get the subjects loaded? Just a thought.
>
>
> On Mon, Jan 17, 2011 at 3:51 PM, kidowell <crui...@gmail.com> wrote:
>
>> I cannot retreive the List<subjects> from book. The save and update of a
>> book when a subject changes its fine, the problem is when retreiving books,
>> It doeesnt retreive their subjects. I need help. Here;s the code.
>>
>> @Entity
>> @Table(name = "book")
>> public class Book implements Serializable, IsSerializable {
>>
>>     @Id
>>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>>     private Key id;
>>     private String bookName;
>>     private String comment;
>>     @OneToMany(mappedBy="book",cascade = CascadeType.ALL)
>>     private List<Subject> subjects;
>>
>> //setters and getters
>>
>> --------------------------------------------------------------------------------------
>>
>> @Entity
>> @Table(name = "subject")
>> public class Subject implements Serializable, IsSerializable {
>>
>>     @Id
>>     @GeneratedValue(strategy = GenerationType.IDENTITY)
>>     private Key id;
>>     private String name;
>>     private int visible;
>>     @Basic
>>     private Text content;
>>     @Basic
>>     @ManyToOne
>>     private Book book;
>> // setters and getters
>>
>>
>> ----------------------------------------------------------------------------------------------------
>>
>>  public List<Book> getBooks() throws GeneralException,
>> BookNotFoundException, NullParameterException {
>>         entityManager = EMF.get().createEntityManager();
>>         List<Book> list;
>>          try {
>>             String sql = "SELECT b FROM Book b";
>>             list =
>> entityManager.createQuery(sql).getResultList();              //this list is
>> retreived with the books but without their subjects
>>         } catch (Exception e) {
>>             throw new GeneralException("Exception in method getBookes: " +
>> e.getMessage());
>>         } finally {
>>             if (entityManager.isOpen()) {
>>                 entityManager.close();
>>             }
>>         }
>>         if (list == null || list.isEmpty()) {
>>
>>             throw new BookNotFoundException("Book not found in method
>> getBookes");
>>         }
>>         return list;
>>     }
>>
>>
>> Please, I need some help.
>>
>> Cheers.
>>
>> --
>> Kido.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Google App Engine for Java" group.
>> To post to this group, send email to
>> google-appengine-java@googlegroups.com.
>> To unsubscribe from this group, send email to
>> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/google-appengine-java?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine for Java" group.
> To post to this group, send email to
> google-appengine-java@googlegroups.com.
> To unsubscribe from this group, send email to
> google-appengine-java+unsubscr...@googlegroups.com<google-appengine-java%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine-java?hl=en.
>



-- 
Cesar Ruiz.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to google-appengine-java@googlegroups.com.
To unsubscribe from this group, send email to 
google-appengine-java+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to