persistence@glassfish.java.net

Re: JPA error

From: Quintin Beukes <quintin_at_skywalk.co.za>
Date: Sat, 22 Aug 2009 18:24:01 +0200

I'm taking a wild one here.

Is it possible that when the session expires, that the Favorite.getMovie()
perhaps returns NULL?

Can you describe the design in terms of your sessions like what is stored in
the session and how do you decide when to store them there, how the movie is
selected, and so on.

Q

On Sat, Aug 22, 2009 at 6:20 PM, measwel <marek_karczewski_at_yahoo.com.au>wrote:

>
> Here is the code:
>
> public void create(Favorite favorite) throws PreexistingEntityException,
> RollbackFailureException, Exception {
> EntityManager em = null;
> try {
> utx.begin();
> em = getEntityManager();
> // get the correct user reference
> Wuser user = favorite.getUser();
> if (user != null) {
> user = em.getReference(user.getClass(), user.getId());
> favorite.setUser(user);
> }
> Movie movie = favorite.getMovie();
> if (movie != null) {
> movie = em.getReference(movie.getClass(), movie.getMovieID());
> favorite.setMovie(movie);
> }
> favorite.setSince(new Date());
> em.persist(favorite);
> // add the new favorite also to the user's favorite collection
> if (user != null) {
> user.getFavorites().add(favorite);
> user = em.merge(user);
> }
> utx.commit();
> } catch (Exception ex) {
> try {
> utx.rollback();
> } catch (Exception re) {
> throw new RollbackFailureException("An error occurred attempting to
> roll back the transaction.", re);
> }
> if (findFavorite(favorite.getFavoriteId()) != null) {
> throw new PreexistingEntityException("Favorite " + favorite + "
> already exists.", ex);
> }
> throw ex;
> } finally {
> if (em != null) {
> em.close();
> }
> }
> }
>
> It works fine, as long as I dont stay inactive too long on the page that
> has
> the button for creating a favorite.
> --
> View this message in context:
> http://www.nabble.com/JPA-error-tp25092854p25095264.html
> Sent from the java.net - glassfish persistence mailing list archive at
> Nabble.com.
>
>


-- 
Quintin Beukes