What I mean is that before you close the entity manager you would need to loop through your list and call the getSubjects() accessor method to cause the entity manager to load the subjects. I am not a JPA developer but I did a quick google search on JPA and it seems that indeed the default fetch option is lazy (any JPA people please chime in if I'm wrong or is different on GAE). It seems that the other option (which I'm not sure is supported on GAE with JPA) is to change the default loading by using FetchType.EAGER in your @OneToMany annotation.
I hope this helps, Stephen On Tue, Jan 18, 2011 at 4:46 AM, Cesar Ruiz <[email protected]> wrote: > 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 <[email protected]> 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 <[email protected]> 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 >>> [email protected]. >>> To unsubscribe from this group, send email to >>> [email protected]<google-appengine-java%[email protected]> >>> . >>> 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 >> [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-appengine-java%[email protected]> >> . >> 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 > [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine-java%[email protected]> > . > 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 [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-appengine-java?hl=en.
