users@glassfish.java.net

Re: UserTransaction for JPA During the whole web request

From: <glassfish_at_javadesktop.org>
Date: Tue, 23 Feb 2010 02:25:07 PST

1. probably not best practice and not recommended for anything other than trivial applications. Depending on your situation (and number of records in the collection) you can always annotate the OneToMany relation with fetch = FetchType.EAGER. This would solve the lazy init problem.

2. Very open to discussion and you could get several alternative "best practice" opinions. Hibernate have had the "open session in view" option for ages and you could solve the problem by using the hibernate JPA implementation. Another option is to use the Spring framework and their transaction annotations at the controller level. This also works very well but requires a good understanding of Spring - however their REST support is excellent (and has many enhancements that are well worth learning)
[Message sent by forum member 'ggierer' (gerald.gierer_at_gieman.com)]

http://forums.java.net/jive/thread.jspa?messageID=388178